Concatenate string and int

This is a discussion on Concatenate string and int within the C Programming forums, part of the General Programming Boards category; It is any way to concatenate a string and an integer? I want to add a loop iteration number to ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    12

    Concatenate string and int

    It is any way to concatenate a string and an integer? I want to add a loop iteration number to the end of a string. Something like 'strcat' would be handy but that only works with strings.

    I would like an like an output something like:

    Code:
    for (i=0; i<3; i++)
    {
         ...code...
         str = "Num0"  
    }
    The number at the end of str increments after each iteration.

  2. #2
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    You could use
    sprintf(str, "Num%d", i);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Replies: 26
    Last Post: 11-30-2007, 02:51 AM
  4. Game Won't Compile
    By jothesmo in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2006, 03:24 PM
  5. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21