i am a beginner
i have tried hours to figure out how to merge 2 strings and a integer into one string.
if anyone can help me on that, i appreciate that.
plz give me some codes too.
thx
i am a beginner
i have tried hours to figure out how to merge 2 strings and a integer into one string.
if anyone can help me on that, i appreciate that.
plz give me some codes too.
thx
See the help on sprintf()
Code:#include <stdio.h> main() { char str[255], *s1 = "The", *s2 = " Number is: "; int num = 666; sprintf(str, "%s%s%d", s1, s2, num); puts(str); }
sorry i did not mention something
after merging 2 strings and 1 number to 1 string, then assig it to another variable
for example,
a = "the", b ="number is" c = 999;
d = a + b + c
so d is a string
thx
That's what sprintf() do. Instead of writing to the screen (like printf()) it writes to the string (str as in Shaik's example).
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
If you'll be displaying it without any further processing after this operation, printf can handle all that if you code in all the formating