I want to create a “fullname” variable from multiple strings. Something like this:
strcpy (fullname, firstname);
strcat (fullname, separator); // separator is initialized at " "
strcat (fullname, middlename);
strcat (fullname, separator);
strcat (fullname, lastname);
This code is repeated at multiple places in my project. I was gonna do a function that does exactly that, but now I wonder if there isn’t a better way to do it.
Any ideas?
You can do also:
But always make sure that the
fullnamepoints to a buffer which can accommodate the total length of all the things you are concatenating.