how to copy 2 char arrays using a method?
Hi, are there any methods to copy to char arrays together
eg
char buf1[256];
char buf2[256];
i tried doing
strcpy(buf1,buf2);
but it doesn''t seem to work
any ideas?
What error is given?
should work.
blah blah blah.
char buf1[256] = "hello, baby!"; char buf2[256]; strcpy(buf2, buf1); cout << buf1 << endl << buf2 << endl;
should work.
blah blah blah.
quote:Original post by johnnyBravo
Hi, are there any methods to copy [two] char arrays together
What do you mean by "together"? strcpy replaces one char array with a null terminated string from the other. strcat takes one string and copies it to the null terminating location of the other string. (ie buf1 = "foo" buf2 = "bar" then strcat(buf1, buf2) = "foobar"). If the char array isn''t a string then you''ll want to just use memcpy(buf1, buf2, 256) to copy the entirety of one array to the other.
Erzengel des Lichtes
Archangel of Light
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement