I'm writing a function that combines first, middle, and last names into another array. Using strcat and strcpy in the following code, everything works fine (they obviously don't take the integer in the middle). Also, the definitions in the main program are:
char First, Middle, Last;
Here's the function that's giving me problems:
I'm really swimming on the integer to put in there. I tried smaller ones and got error messages (or crashes), and these were just my last experimental values before turning to you guys. The message I get when I run the program goes something like: "application wrote to memory after end of heap buffer" and it gives a buffer location, too.Code:
char * combineNames(const char *First, const char *Middle, const char *Last)
char *FullName = new char;
strcpy_s(FullName, 15*4, Last);
strcat_s(FullName, 15*4, ", ");
strcat_s(FullName, 15*4, First);
strcat_s(FullName, 15*4, " ");
strcat_s(FullName, 15*4, Middle);
I also think the number in the middle is supposed to be a number of bytes rather than number of places in the array.
As I say, using strcpy and strcat with no integer, the whole thing works fine, but it looks like those are deprecated according to warnings in MS suggesting using strcpy_s instead.