English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

say there is a string and a numeric value
char str[15] = "outref"
int num = 100
i need to append this num to str - so i need to convert 'num' to string value and append it with 'str'. how is it possible?? is there any other way to do it?? please tell me.
thank you

2007-04-10 10:54:54 · 3 answers · asked by Anonymous in Computers & Internet Programming & Design

3 answers

sprintf(newstring, "%s %d", str, num);

2007-04-10 10:57:36 · answer #1 · answered by mackn 3 · 0 0

im not sure if this works in C, but there is a function called itoa(). to use it:

char str[15] = "outref";
char charnum[10];
int num = 100;

itoa(num, charnum, 10);
strcat(str, charnum);
//now str = outref100

2007-04-11 01:53:37 · answer #2 · answered by justme 7 · 0 0

You can do this with sprintf().

int i = 5;
char str[10];

sprintf(str, "blah %i", i); // str is now "blah 5"

2007-04-10 10:57:58 · answer #3 · answered by Anonymous · 0 0

fedest.com, questions and answers