On Sep 4, 10:59 pm, Ashit Vora <a.k.v...@gmail.comwrote:
Quote:
I friends,
I 'm facing a weird prob.
>
the code is
>
int total_buf_size=100;
char *buf;
int type= 0xFE10;
>
buf =(char*) malloc (total_buf_size);
>
memcpy(buf,&type, 10);
printf("Buf:: %s\n",buf);
>
The printf doesnt print anything but just "Buf::"
>
can anyone pls help me out resolve this???
Thanks a ton
ObCLC: You're invoking undefined behavior, anything could happen, etc.
There are a number of problems.
First, why are you copying 10 bytes? Your integer probably isn't that
large. You probably want to use sizeof(int) here instead.
Second, what kind of system are you on? If it is big-endian with 32-
bit integers, the first byte of type (which will be the first byte in
buf) would be the most-significant byte, which is 0, and acts as the
terminating null of the string.
Just what is it that you're trying to accomplish, and what do you
expect it to do? If you want to print out the character with value
0xFE, just do
printf("character looks like %c\n", 0xfe);
or even
puts("character is \xfe");