Normally you can print a string in C like this..
printf("No record with name %s found\n", inputString);
But I wanted to make a string out of it, how I can do it? I am looking for something like this..
char *str = ("No record with name %s found\n", inputString);
I hope it is clear what I am looking for...
One option would be to use sprintf
, which works just like printf
but takes as its first parameter a pointer to the buffer into which it should place the resulting string.
It is preferable to use snprintf
, which takes an additional parameter containing the length of the buffer to prevent buffer overruns. For example:
char buffer[1024];
snprintf(buffer, 1024, "No record with name %s found\n", inputString);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With