3. Write a program that contains four arrays. Three of the arrays should contain your
first name, middle initial, and last name. Use the string-copying function presented
in today’s lesson to copy these strings together into the fourth array, full name.
Problem is, I'm using "strcpy" but I can only copy one string in the other, and if I do it again, it overwrites the first one, I'm out of solutions, any ideas?
Thank you very much, I curse the day I bought this book, but I'll keep on trying to finish it since I started, forgot to ask though, if you have any other material that could help me, I would appreciate it a lot.
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
usingnamespace std;
main ()
{
char cArray1 [] = "Jesse";
char cArray2 [] = "Micheal";
char cArray3 [] = "Leonard";
char FullName [100];
strcat(FullName, cArray3, cArray2, cArray1);
cout << "This is my full name " << FullName <<endl;
system("PAUSE");
return 0;
}
When I try it, I get an error and I'm sent to the string.h, what am I doing wrong?
The error is here, _CRTIMP char* __cdecl strcat (char*, constchar*);, it says there are too many arguments, do I need to write the command in some other manner?
strcpy is usually used when copying to an empty string. While strcat appends one string to another. You should use strncat instead of strcat because strncat has a length check preventing buffer overflow.