Command line character problem

Discussion in 'C Programming' started by mdh, Sep 29, 2008.

  1. mdh

    mdh Guest

    Hi all,
    I have a file, whose path is:

    "/Users/m/k&R/test_file"


    How do I include the '&' in a string constant? ( I need this for the
    example on p162). I have tried to use the Hex notation x26, as in

    "/Users/m/k\x26R/test_file".

    On it's own, an ampersand in the literal causes an error. Using the
    escape sequence, I get no error, but neither do I get the result I
    want! :)

    Could anyone give some guidance.

    Thank you as usual.
    mdh, Sep 29, 2008
    #1
    1. Advertising

  2. mdh

    viza Guest

    Hi

    On Mon, 29 Sep 2008 05:21:35 -0700, mdh wrote:

    > "/Users/m/k&R/test_file"
    >
    > How do I include the '&' in a string constant? ( I need this for the
    > example on p162). I have tried to use the Hex notation x26, as in
    >
    > "/Users/m/k\x26R/test_file".
    >
    > On it's own, an ampersand in the literal causes an error. Using the
    > escape sequence, I get no error, but neither do I get the result I want!


    There is nothing special about the ampersand in a C string literal, you
    have got something else wrong.

    Post the exact code you tried to compile and the exact message you
    received.
    viza, Sep 29, 2008
    #2
    1. Advertising

  3. mdh

    Guest

    On Sep 29, 3:21 pm, mdh <> wrote:
    > Hi all,
    > I have a file, whose path is:
    >
    > "/Users/m/k&R/test_file"
    >
    > How do I include the '&' in a string constant? ( I need this for the
    > example on p162). I have tried to use the Hex notation x26, as in
    >
    > "/Users/m/k\x26R/test_file".
    >
    > On it's own, an ampersand in the literal causes an error. Using the
    > escape sequence, I get no error, but neither do I get the result I
    > want! :)


    The error you get is not related to the ampersand.
    C guarantees that '&' > 0, but not that '&' == 0x26.
    (not all systems have ASCII)

    What was the original problem that led you to believe the ampresand
    was the problem?
    , Sep 29, 2008
    #3
  4. mdh

    mdh Guest

    On Sep 29, 5:36 am, Richard Heathfield <> wrote:
    >
    >
    > This is nothing to do with C, and everything to do with your filesystem.
    >
    > It may be worth trying this:
    >
    > "/Users/m/k\\&R/test_file"
    >
    > but really this is a shell question, not a C question.


    Hi Richard...yes...I was afraid that it would be this. Thanks.
    mdh, Sep 29, 2008
    #4
  5. mdh

    mdh Guest

    On Sep 29, 5:36 am, wrote:
    > On Sep 29, 3:21 pm, mdh <> wrote:
    >
    > > Hi all,
    > > I have a file, whose path is:

    >
    > > "/Users/m/k&R/test_file"

    >


    >
    > The error you get is not related to the ampersand.
    > C guarantees that '&' > 0, but not that '&' == 0x26.
    > (not all systems have ASCII)
    >
    >



    Thanks for your input.
    mdh, Sep 29, 2008
    #5
  6. mdh

    mdh Guest

    On Sep 29, 5:41 am, Eric Sosman <> wrote:
    >
    >
    > </off-topic>
    >
    >      When you have questions in the future, please try to give
    > a fuller description of your problem.  You say that something
    > you tried gave "an error," but you coyly conceal the nature of
    > that error ...  Don't rely on us (and certainly not on me!) to
    > be able to intuit all the details you omit; our crystal balls
    > are either cloudy or foreclosed on, and our intuition may lead
    > us to diagnose some problem entirely unlike the one that afflicts
    > you.  If so, the time you've wasted reading my non-answer is
    > your own fault, and your own punishment.  Harrrumph!



    Point taken...you are the last person I wish to alienate.
    mdh, Sep 29, 2008
    #6
  7. mdh <> writes:
    > I have a file, whose path is:
    >
    > "/Users/m/k&R/test_file"
    >
    >
    > How do I include the '&' in a string constant? ( I need this for the
    > example on p162).


    Precisely as you've done above.

    > I have tried to use the Hex notation x26, as in
    >
    > "/Users/m/k\x26R/test_file".


    That will give you a character with the value 0x26, which the standard
    does not guarntee to be '&'. If it is (as it almost certainly is on
    your system), "...\x26..." means *exactly* the same thing as
    "...&...", so you can't expect it to solve your problem. If it isn't,
    then it obviously won't solve your problem.

    > On it's own, an ampersand in the literal causes an error.


    No, it doesn't, at least not directly. An ampersand is a perfectly
    legal character in a string literal. An ampersand in the resulting
    string value may indirectly cause some other error, but you haven't
    given us a clue what that error might be.

    > Using the
    > escape sequence, I get no error, but neither do I get the result I
    > want! :)


    How are we supposed to know what result you want?

    > Could anyone give some guidance.


    Yes, ask better questions.

    I can guess with some confidence what your problem is. I've written
    up a fairly detailed explanation, but I won't post it here, since it's
    system-specific; if your e-mail address is valid, I'll send it to you
    directly. But if you want a useful answer, you'll have to provide
    more information. Usually the best thing is to post a small,
    complete, compilable program that illustrates your problem, not just a
    single string literal removed from any context. (Hint: I'll bet
    you're passing it to system().)

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Sep 29, 2008
    #7
    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. Tim Tyler
    Replies:
    1
    Views:
    1,134
    Tom McGlynn
    Jun 27, 2003
  2. Jari Kujansuu
    Replies:
    1
    Views:
    4,890
    Juha Laiho
    Jun 2, 2005
  3. Replies:
    4
    Views:
    2,906
    Robert Mark Bram
    Oct 31, 2006
  4. Dawn Minnis
    Replies:
    9
    Views:
    350
    Dave Thompson
    Feb 28, 2005
  5. Dib Urim
    Replies:
    4
    Views:
    184
    Michele Dondi
    Dec 3, 2003
Loading...

Share This Page