Thread: Converting integer to string???

  1. #1

    Converting integer to string???

    Hi all,

    I was trying to concatenate an integer with a string. I tried doing:

    char *string1;
    int age = 2;

    string1 = "my age is ";

    string1 = strcat(string1, age);

    but this failed. Does anyone know how I can convert an integer (age in my code) to a string so that I can use it in the strcat function?

    Thanks a lot!

  2. #2
    Registered User Strider's Avatar
    Join Date
    Aug 2001
    sprintf(string1, "My age is %d", age);
    One Ring to rule them all, One Ring to find them,
    One Ring to bring them all and in the darkness bind them
    In the Land of Mordor where the Shadows lie.

  3. #3
    Registered User
    Join Date
    Nov 2001
    i think what that other dude said in so few words cant...strcat was made to take in 2 strings...maybe chars too, thats it...pass it anything else it gets mad

  4. #4
    Registered User
    Join Date
    Nov 2001
    just realized it can take chars since strings are chars...duh...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Converting a string to an integer
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 08-31-2001, 10:01 PM