#include <iostream>
using namespace std;
int main()
{
char buffer[8];
int field=534;
memcpy(buffer,&field,sizeof(field));
cout<<buffer<<endl;
return 0;
}
This returns an empty buffer. Why?
Basically looking for an alternative to sprintf to convert int to char buffer.
Itoa is not available.
Thoughts? Better alternatives?
You will have to use sprintf or itoa to convert a binary int to an ascii string.
The representation if ints and and char arrays is totally different and ints can conytain bytes with a value of zero but strings can only have that as the last byte.
for example
Takes 0 – in int it is represented by 4 bytes with values 0 whilst ) as a string has the first two bytes of 48 and 0 so no simple cast will chnage this