In article <1161628848.076461.96240@h48g2000cwc.googlegroups. com>,
danu <danu82@gmail.comwrote:
Quote:
>But in my man pages: uint32_t htonl(uint32_t hostlong);
Hmmm, that isn't what my man page says, but I see it isn't defined
in POSIX.1; uint32_t is what opengroup.org has documented for Unix 97.
Quote:
>anyways, this shouldn't be the problem. All I want to do is store an
>unsigned integer into the first 4 bytes of a char array:
Quote:
>int main () {
char buf[512];
unsigned int temp;
temp = 25115555;
>
memcpy(buf, &temp, 4) ;
>
>}
Quote:
>shouldn't this memcpy statement suppose to stick that temp value in to
>the first 4 bytes of the buf?
It does in my test, on a system that happens to use 32 bit int.
On a completely different system that I tried, it was easiest to
modify to unsigned char to get my test output to work:
printf( "%02X.%02X.%02X.%02X\n", buf[0], buf[1], buf[2], buf[3] );
With signed chars, the first version output
../tmp 1002./tht
FFFFFFA3.3B.7F.01
because of the sign extension as the signed char was converted to
int (by the default argument promotions.)
--
Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us. -- Ecclesiastes