Thread: Smarter ways to define MACRO to strings?

  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
    477
    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, 05: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, 02: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