Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Command line character problem (http://www.velocityreviews.com/forums/t637443-command-line-character-problem.html)

mdh 09-29-2008 12:21 PM

Command line character problem
 
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.


viza 09-29-2008 12:28 PM

Re: Command line character problem
 
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.


vippstar@gmail.com 09-29-2008 12:36 PM

Re: Command line character problem
 
On Sep 29, 3:21 pm, mdh <m...@comcast.net> 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?

mdh 09-29-2008 12:41 PM

Re: Command line character problem
 
On Sep 29, 5:36*am, Richard Heathfield <r...@see.sig.invalid> 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 09-29-2008 12:42 PM

Re: Command line character problem
 
On Sep 29, 5:36*am, vipps...@gmail.com wrote:
> On Sep 29, 3:21 pm, mdh <m...@comcast.net> 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 09-29-2008 12:47 PM

Re: Command line character problem
 
On Sep 29, 5:41*am, Eric Sosman <esos...@ieee-dot-org.invalid> 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.


Keith Thompson 09-29-2008 05:13 PM

Re: Command line character problem
 
mdh <mdeh@comcast.net> 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) kst-u@mib.org <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"


All times are GMT. The time now is 01:34 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.