Smarter ways to define MACRO to strings?

This is a discussion on Smarter ways to define MACRO to strings? within the C Programming forums, part of the General Programming Boards category; Hello everyone, I have a number of strings in an array, "FILE1", "FILE2", "FILE3", ... , "FILEN" I want to ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    Smarter ways to define MACRO to strings?

    Hello everyone,


    I have a number of strings in an array,

    "FILE1", "FILE2", "FILE3", ... , "FILEN"

    I want to add the common prefix to all the string, like

    (for example, the common prefix is "FOO")

    "FOOFILE1", "FOOFILE2", "FOOFILE3", ... , "FOOFILEN".

    Are there any smarter ways to use a macro to define all of them altogether?


    thanks in advance,
    George

  2. #2
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    478
    Code:
    char prefix[] = "FOO", file[] = "file", emptyarray[strlen(prefix) + strlen(file) + 5];
    int number = 1;
    
    for(i; i <= 10; i++)
    {
         sprintf(emptyarray, "%s%s%d", prefix, file, number);
    
         // .. do something ..
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with Bitmap Display
    By The Brain in forum Windows Programming
    Replies: 7
    Last Post: 03-23-2009, 06:33 AM
  2. Would someone solve my problem?
    By Lonners in forum C Programming
    Replies: 9
    Last Post: 01-19-2008, 06:58 PM
  3. Accessing syscalls from C
    By lilcoder in forum C Programming
    Replies: 17
    Last Post: 09-19-2007, 03:27 PM
  4. edit controls in dialogs
    By Homunculus in forum Windows Programming
    Replies: 10
    Last Post: 02-23-2006, 03:38 PM
  5. build errors migrated from dx9b to dx9c sdk
    By reanimated in forum Game Programming
    Replies: 4
    Last Post: 12-17-2004, 07:35 AM

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