how to copy 2 char arrays using a method?

Started by
4 comments, last by johnnyBravo 19 years, 11 months ago
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?
Advertisement
Are you trying to swap them?
Not giving is not stealing.
Maybe you want memcpy() or std::copy() instead?
What error is given?

	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
----Erzengel des Lichtes光の大天使Archangel of LightEverything has a use. You must know that use, and when to properly use the effects.♀≈♂?
ok ill use mem copy...

This topic is closed to new replies.

Advertisement