home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!gossip.pyramid.com!decwrl!pacbell.com!tandem!UB.com!pippen.ub.com!rfries
- From: rfries@sceng.ub.com (Robert Fries)
- Subject: Re: Preprocessor question
- Message-ID: <rfries.178@sceng.ub.com>
- Keywords: Preprocessor, string
- Sender: news@pippen.ub.com (The Daily News)
- Nntp-Posting-Host: 128.203.1.151
- Organization: Ungermann Bass
- References: <1993Jan25.161425.27962@bnrmtl.bnr.ca>
- Date: Mon, 25 Jan 1993 17:34:17 GMT
- Lines: 53
-
- In article <1993Jan25.161425.27962@bnrmtl.bnr.ca> karim@bnrmtl.bnr.ca (Karim Younes) writes:
-
- >I am trying to have a #defined variable recognized by the
- >preprocessor inside a string. In other words, I want to
- >do something like this:
-
- >#define JUNK 50
- >static char *junk = "JUNK ways to leave your lover."
-
- >Now the preprocessor ignores JUNK, because it is inside the double
- >quotes. Is there any way to get around this ? Please respond
- >by e-mail or by followup, I will post a summary if needed. Thanks.
-
- >--
- >Karim "Kouki" Younes Bell-Northern Research
- >karim@bnr.ca Montreal, Canada
-
-
- Adjacent strings are concatenated, at least in ANSI C.
- So you can do:
-
- #define JUNK "50"
- static char *junk = JUNK" ways to leave your lover."
-
- During pre-processing, the definition of junk becomes:
- static char *junk = "50"" ways to leave your lover."
-
- The two string are concatenated, so junk becomes a pointer to the following
- string:
- "50 ways to leave your lover."
-
- In your example, you wanted to replace the first word in a string.
- If you wanted to replace a word somewhere in the middle of the string,
- you could do the following:
-
- #define JUNK "50"
- char *junk = "There are "JUNK" ways to leave your lover."
-
- In this case three strings are concatenated into one.
-
- I hope this helps.
-
- Robert
-
-
- //////////////////////////////////////////////////////////////////////////
- Robert Fries
- Ungermann-Bass Inc.
-
- DISCLAIMER:
- Opinions contained herein are my own, and are not necessarily those
- of Ungermann-Bass.
- //////////////////////////////////////////////////////////////////////////
-