Page 1 of 1

Copying Integers to Character Array (In C)

Posted: Sat Apr 21, 2007 12:52 pm
by TS_Death_Angel
Hi. I have an integer (4 bytes, no more, no less) which I need to copy into an unsigned character array. There has to be some simple way to do it, and if you know it, please reply. The way I'm doing it at the moment is sprintf'ing the integer to a string as a hexadecimal number, converting every two (text) bytes into an integral byte and placing it into the array. Very inefficient, and it is imperative I find a better way of doing it :<

Thanks.

Posted: Sat Apr 21, 2007 1:07 pm
by neel_basu
Start mod(%) it from right and store it in an array.
and then
either -> cast char data type to that array.
if that doesn't work
Converts those values in the array to their ASCII Values.
And then cast char data type to that array.

I have never tried that.

In php string type casting is enough.