Adding group of integers to string

This is a discussion on Adding group of integers to string within the C Programming forums, part of the General Programming Boards category; Hey guys, I am trying to throw in a couple integer values to a char[]. In the array I have ...

  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
    2,268
    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, 06: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, 08:49 AM
  4. Adding integers to a string
    By Kyoto Oshiro in forum C++ Programming
    Replies: 3
    Last Post: 02-23-2004, 07: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


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