There is a function that takes string as a parameter/argument.
Func(char* strA)
{
...
}
I have two strings;
#define FIRST "first"
char efg[] = " second";
I want to basically send "first second" as argument to Func(strA), but I do not want to use strcat(FIRST, efg); as it would permanently change my macro FIRST.
Is there a way to send "first second" as argument without upsetting the macro above?
You can use of sprintf function to write first in a temp buffer:
Give it a Try!!
Note: don’t forget free() dynamic allocated memory.
Description:
The
sprintf()function is just likeprintf(), except that the output is sent to buffer. The return value is the number of characters written.