memset which we used for intialinzation of array in c this  work only for character not for integer and memcopy will wok same character not for intger
 
it may  work  in vc++
if u have
char buffer[5];
char temp[4];
buffer[0] = 'A';
temp[0] = B;
temp[1] = D;
temp[2] = E;
temp[3] = W;
and U do this: memcpy(buffer+1, &temp, sizeof(temp));
TheN buffer contain ABDEW

 


Soewandi Wirjawan <[EMAIL PROTECTED]> wrote:

if i have this

char buffer[5];
int temp[4];

buffer[0] = 'A';
temp[0] = 3;
temp[1] = 1;
temp[2] = 2;
temp[3] = 2;

and i do this: memcpy(buffer+1, &temp, sizeof(temp));
will the buffer contain A3122? because that's the
result that i wanted, and somehow i only got the A
part ...

thanks

--- Mark Van Peteghem <[EMAIL PROTECTED]>
wrote:

>
> soewandi_w wrote:
>
> >
> >
> > Can anybody explain to me how memcpy works? I
> tried to copy an int
> > array to a char array, here's how i did it:
> >
> > memcpy (char_array+1, &int_array,
> sizeof(int_array));
> >
> > the char array already has an element in the slot
> 0, but somehow,
> > the memcpy didn't work, it didn't copy the
> int_array part to the
> > char_array since when i tried to print it out, it
> only gave me the
> > char part ...
>
> memcpy simply copies bytes from one place in memory
> to another. How many
> bytes is given by the thrid argument. But in your
> code you write
> sizeof(int_array). How is int_array defined? If it
> is defined like int
> *int_array; then sizeof(int_array) is 4. If it is
> defined like int
> int_array[100]; then sizeof(int_array) is 400.
> Another thing, the second
> argument probably has to be int_array, not
> &int_array. Also remember
> that the third argument is the number of bytes, not
> the number of
> elements in your array.
>
> --
>   Mark Van Peteghem
>   http://www.q-mentum.com -- easier and more
> powerful unit testing>
>
>
>
>



           
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com





To unsubscribe : [EMAIL PROTECTED]





Do you Yahoo!?
vote.yahoo.com - Register online to vote today!

To unsubscribe : [EMAIL PROTECTED]




Yahoo! Groups Sponsor
ADVERTISEMENT
click here
Web Bug from http://us.adserver.yahoo.com/l?M=294855.5468653.6549235.3001176/D=groups/S=:HM/A=2376776/rand=471049651


Yahoo! Groups Links

Reply via email to