Reputation: 22810
hello im trying to add a space between two strings and strcopy them into a variable
in php we could just add them with a +
front_name = "hello";
back_name = "world";
full_name = strcpy(m[index].p.something, front_name + " " + backname);
// should output hello world
what is the equivalent or the right way to do it in c?
Upvotes: 2
Views: 2905
Reputation: 17258
sprintf would be ideal provided the buffer that the strings are copied to is large anough:
e.g.
char buffer[512];
sprintf(buffer, "%s %s", front_name, backname);
Upvotes: 5
Reputation: 122383
Assuming that result
has enough space, use this:
sprintf(result, "%s %s", front_name, backname);
Upvotes: 4