c - How to integrate int variable in a string? -
#include<stdio.h> main() { int i=100; char temp[]="value of **** , can write int inside string"; printf("\n%s\n",temp); }
i need print value of i
inside string. output as:
value of 100 , can write int inside string
what should write @ place of **** or how should change code output above? don't want use printf
print output.
you can use sprintf
'print' string char array, printf
prints screen:
char temp[256]; sprintf(temp, "value of %d , can write int inside string", i);
note need make sure buffer large enough! or use snprintf
specify maximum string/text length, not write outside of buffer.
Comments
Post a Comment