Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Smarter ways to define MACRO to strings?

Reply
Thread Tools

Smarter ways to define MACRO to strings?

 
 
George2
Guest
Posts: n/a
 
      11-22-2007
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
 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      11-22-2007
In article
<(E-Mail Removed)>,
George2 <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
any smarter ways to design this tree structure George2 C++ 0 04-18-2008 09:59 AM
Smarter than BigDecimal Class Luc The Perverse Java 6 07-17-2006 07:29 PM
smarter enums Mark A. Gibbs C++ 27 07-18-2004 02:36 PM
#define macro to enclose an older macro with strings Dead RAM C++ 20 07-14-2004 10:58 AM
WARNING: MusicMatch Jukebox is smarter than you (like XP) Roy Jensen Computer Support 31 01-09-2004 09:15 PM



Advertisments