there's a difference ... i don't want to see a formated string ... i want to create one , for example:

char s[128];
gets(s);
int d = 43;
char c = 'D';
format(s,sizeof(s),"String is: %s | Integer is: %d | Caracter is: %c",s,d,c);
and all this will be putted in s and if i want to see the vals , i do:
cout << s;
or
printf("%s",s);

Or something else and will print:

String is: (what i typed) | Integer is: 43 | Caracter is: D

Edited 6 Years Ago by charqus: n/a

>there's a difference ...
Only in your mind. What you described is exactly what sprintf will do for you.

First off, anyone using gets(s); needs their head examining.

> format(s,sizeof(s),"String is: %s | Integer is: %d | Caracter is: %c",s,d,c); And this differs from the following in what way? snprintf(s,sizeof(s),"String is: %s | Integer is: %d | Caracter is: %c",s,d,c); Further (what, you mean there's more?) format(s,sizeof(s),"String is: %s | Integer is: %d | Caracter is: %c",s,d,c); Using the same buffer for input AND output is real bad mojo (if you want to be technical, it's undefined behaviour).

All you're likely to end up with is a string full of
String is: String is: String is: String is: String is: String is:
or something worse, like wondering where your OS reinstall disks are.

Comments
Nice.
This article has been dead for over six months. Start a new discussion instead.