how to surround a constant with quotes?

Discussion in 'C Programming' started by .rhavin grobert, Mar 13, 2007.

  1. lets say i do a

    #define foo AbCdEf

    now i want to do *something* that is NOT

    #define foo2 "AbCdEf"

    but has the same effect, ... so how can i tell the preprocessor "do me
    some quotes around my foo-constant"?

    -.rhavin;)
     
    .rhavin grobert, Mar 13, 2007
    #1
    1. Advertising

  2. ..rhavin grobert said:

    > lets say i do a
    >
    > #define foo AbCdEf
    >
    > now i want to do *something* that is NOT
    >
    > #define foo2 "AbCdEf"
    >
    > but has the same effect, ... so how can i tell the preprocessor "do me
    > some quotes around my foo-constant"?


    I'm not exactly sure which of the FAQs you're asking, but whichever one
    it is, it's answered in Section 10 of the FAQ.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at the above domain, - www.
     
    Richard Heathfield, Mar 13, 2007
    #2
    1. Advertising

  3. .rhavin grobert

    bytebro Guest

    On 13 Mar, 13:57, ".rhavin grobert" <> wrote:
    > lets say i do a
    >
    > #define foo AbCdEf
    >
    > now i want to do *something* that is NOT
    >
    > #define foo2 "AbCdEf"
    >
    > but has the same effect, ... so how can i tell the preprocessor "do me
    > some quotes around my foo-constant"?
    >
    > -.rhavin;)


    #define foo(x) #x
    ..
    ..
    printf (foo(Put me some quotes around this\n));
    ..
     
    bytebro, Mar 13, 2007
    #3
  4. .rhavin grobert

    santosh Guest

    ..rhavin grobert wrote:
    > lets say i do a
    >
    > #define foo AbCdEf
    >
    > now i want to do *something* that is NOT
    >
    > #define foo2 "AbCdEf"
    >
    > but has the same effect, ... so how can i tell the preprocessor "do me
    > some quotes around my foo-constant"?


    Yes.

    #define foo(x) #x

    What's wrong with the above solution for what you're trying to do?
     
    santosh, Mar 13, 2007
    #4
  5. .rhavin grobert

    pete Guest

    ..rhavin grobert wrote:
    >
    > lets say i do a
    >
    > #define foo AbCdEf
    >
    > now i want to do *something* that is NOT
    >
    > #define foo2 "AbCdEf"
    >
    > but has the same effect, ... so how can i tell the preprocessor "do me
    > some quotes around my foo-constant"?


    /* BEGIN new.c */

    #include <stdio.h>

    #define foo AbCdEf
    #define str(x) # x
    #define xstr(x) str(x)

    int main(void)
    {
    puts(xstr(foo));
    return 0;
    }

    /* END new.c */

    --
    pete
     
    pete, Mar 13, 2007
    #5
  6. .rhavin grobert

    Old Wolf Guest

    On Mar 14, 3:59 am, "santosh" <> wrote:
    > .rhavin grobert wrote:
    > > lets say i do a
    > > #define foo AbCdEf
    > > now i want to do *something* that is NOT
    > > #define foo2 "AbCdEf"

    >
    > > but has the same effect,

    >
    > #define foo(x) #x
    >
    > What's wrong with the above solution for what you're trying to do?


    Well, he would need to do it in several stages:
    #define BAR(x) #x
    #define BAZ(x) BAR(x)
    #define foo2 BAZ(foo)
     
    Old Wolf, Mar 13, 2007
    #6
    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. Chris White

    Quotes/Double Quotes in Image Control

    Chris White, Sep 22, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,906
    Hermit Dave
    Sep 22, 2004
  2. Bruce W...1
    Replies:
    4
    Views:
    3,292
    Sid Ismail
    Oct 19, 2003
  3. comcast
    Replies:
    5
    Views:
    423
    giganews
    Mar 3, 2004
  4. Ivan Vega
    Replies:
    8
    Views:
    102
    Ivan V.
    Jul 4, 2007
  5. toralf
    Replies:
    5
    Views:
    188
    toralf
    Sep 14, 2009
Loading...

Share This Page