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")


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

    thanks in advance,
    George2, Nov 22, 2007
    1. Advertisements

  2. George2

    santosh Guest

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

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

    "FOO" "FILE2"



    During runtime you can use sprintf() or strcat()/strncat() do to the
    same as well.
    santosh, Nov 22, 2007
    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.