Reputation: 1903
Is there a standard C function that allows you to build strings using format specifiers?
Right now I'm doing this:
char buffer[256];
char *name = "Fred";
strcpy(buffer, "Hello, ");
strcat(buffer, name);
strcat(buffer, ". How are you today?\n");
Is there a way to add the message to buffer in one function?
Something like this:
makestr(buffer, "Hello, %s. How are you today?\n", name);
Upvotes: 2
Views: 1415
Reputation: 25750
Be careful when using it because sprintf is not a safe function and can suffer from buffer overflows.
Upvotes: 8