Command line character problem

M

mdh

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.
 
V

viza

Hi

"/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.
 
V

vippstar

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?
 
M

mdh

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.
 
M

mdh

</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.
 
K

Keith Thompson

mdh said:
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().)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top