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. Advertising

  2. George2

    santosh Guest

    In article
    <>,
    George2 <> wrote on Thursday 22 Nov 2007 1:29
    pm:

    > 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?


    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. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark A. Gibbs

    smarter enums

    Mark A. Gibbs, Jul 12, 2004, in forum: C++
    Replies:
    27
    Views:
    2,720
    Mark A. Gibbs
    Jul 18, 2004
  2. Dead RAM
    Replies:
    20
    Views:
    1,116
    John Harrison
    Jul 14, 2004
  3. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    767
    Malcolm
    Jun 24, 2006
  4. George2
    Replies:
    0
    Views:
    597
    George2
    Apr 18, 2008
  5. James Harris

    Ways to define C constants

    James Harris, Jun 2, 2014, in forum: C Programming
    Replies:
    46
    Views:
    204
    Jorgen Grahn
    Jun 6, 2014
Loading...

Share This Page