Thread: Adding group of integers to string

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    18

    Adding group of integers to string

    Hey guys,

    I am trying to throw in a couple integer values to a char[].
    In the array I have the date broken down with the struct tm variables into year month and day. Here is what I have.

    Code:
    char fileName[] = "Catalog_%i_%i_%i_am.txt", year, month, day;
    I'm pretty sure the syntax is wrong but I cannot find anything online about doing this.

    It compiles fine and when it runs the output is:
    Catalog_%i_%i_%i_am.txt

    It leaves the '%i' in there.

    Thank you for your time.
    Dominic

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    This looks like a good use for sprintf().

    Instead of printing to the screen, "sprintf()" prints to a buffer.

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    18
    Thank you that worked great!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adding Long Integers!
    By alireza beygi in forum C Programming
    Replies: 1
    Last Post: 12-17-2011, 07:11 AM
  2. Question about adding integers to char
    By blueshift1980 in forum C++ Programming
    Replies: 6
    Last Post: 04-16-2009, 12:51 PM
  3. adding 16bit and 32 bit integers
    By kris_perry2k in forum C Programming
    Replies: 2
    Last Post: 12-08-2005, 09:49 AM
  4. Adding integers to a string
    By Kyoto Oshiro in forum C++ Programming
    Replies: 3
    Last Post: 02-23-2004, 08:01 AM
  5. C++ help!!!!! Adding integers
    By PR1MO in forum C++ Programming
    Replies: 3
    Last Post: 04-30-2003, 05:40 PM

Tags for this Thread