Smarter ways to define MACRO to strings?

G

George2

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
 
S

santosh

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top