Advertisements

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.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!