Smarter ways to define MACRO to strings?

Discussion in 'C Programming' started by George2, Nov 22, 2007.

  1. George2

    George2 Guest

    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
     
    George2, Nov 22, 2007
    #1
    1. Advertisements

  2. George2

    santosh Guest

    Yes. Just write "FOOFILE1", ..., instead.

    Also adjacent string literals are concatenated by the compiler. Thus:

    "FOO" "FILE2"

    becomes

    "FOOFILE2"

    During runtime you can use sprintf() or strcat()/strncat() do to the
    same as well.
     
    santosh, Nov 22, 2007
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.