Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

johnnyBravo

how to copy 2 char arrays using a method?

This topic is 5113 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!