Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string and integer concatenation

Status
Not open for further replies.

powerb23

Technical User
Sep 11, 2003
11
0
0
US
How would i concatenate strings and integers.
For example

char* m = "there are ";
char* n = " days"
int x = 3;

i would like something like
char* ans = "there are 3 days"

Your help will be appreciated
 
Code:
#include <stdio.h>

int main(void)
{
   char m[] = "there are ";
   char n[] = " days";
   int x = 3;
   char ans[sizeof m + sizeof n + /*let's say*/12];
   [b]sprintf[/b](ans, "%s%d%s", m, x, n);
   puts(ans);
   return 0;
}

/* my output
there are 3 days
*/
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top