473,548 Members | 2,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Command line character problem

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.

Sep 29 '08 #1
8 3055
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.

Sep 29 '08 #2
mdh said:
Hi all,
I have a file, whose path is:

"/Users/m/k&R/test_file"
How do I include the '&' in a string constant?
The answer to your question is right there in the question itself.

"/Users/m/k&R/test_file"
On it's own, an ampersand in the literal causes an error.
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.

If all you want is a quick fix, why not rename the directory to
/Users/m/kandr/test_file ? Just a thought.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Sep 29 '08 #3
On Sep 29, 3:21 pm, mdh <m...@comcast.n etwrote:
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 '08 #4
mdh
On Sep 29, 5:36*am, Richard Heathfield <r...@see.sig.i nvalidwrote:
>

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.
Sep 29 '08 #5
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! :-)
Since there's nothing in any way special about the ampersand
in a "string constant" or "literal" appearing in C source code,
I suspect you're talking about something else entirely.

My guess, from your Subject line, is that you're having
trouble providing the file name to the program as a command-line
argument. Perhaps the "command interpreter" through which you
launch programs attaches special meaning to the ampersand -- many
Unix "shells" do. If that's the problem, your question isn't
about C at all, but about how to use the command line on your
system (whatever it is). Try a forum that discusses your system.

<off-topic>

If you're using a Unix system,

programname /Users/m/k\&r/test_file

should work with most shells.

</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!

--
Eric Sosman
es*****@ieee-dot-org.invalid
Sep 29 '08 #6
mdh
On Sep 29, 5:36*am, vipps...@gmail. com wrote:
On Sep 29, 3:21 pm, mdh <m...@comcast.n etwrote:
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.
Sep 29 '08 #7
mdh
On Sep 29, 5:41*am, Eric Sosman <esos...@ieee-dot-org.invalidwrot e:
>

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

Sep 29 '08 #8
mdh <md**@comcast.n etwrites:
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_Keit h) ks***@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"
Sep 29 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3110
by: Fraser Campbell | last post by:
Hi, We're trying enter polish language into mysql. My understanding is that polish language uses iso-8859-2 character set. I am cutting and pasting polish text from a web browser (Konqueror) into the mysql command line client running in a terminal window (konsole). MySQL server is version 4.0.12 running on a remote Linux server that I...
8
1920
by: MarkE | last post by:
I'm sure someone else has posted a similar problem but I can't find it, nor the solution... I have a python script which accepts a command line argument. E.g. python.exe myscript.py -n Foo I build this as part of a package using distutils with the bdist_wininst option on a Windows 2K (SP4) machine. I have tested installing and running...
2
7825
by: Pascal Deparis | last post by:
Hi, I've got a problem with the DB2 Command Line Processor, in V8, FP1. The databases have been created on an AIX server (version 4.3.3). Have a look at this: >db2 ? list DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned: SQL1024N A...
6
2922
by: Edd Dawson | last post by:
Hi. I have a strange problem involving the passing of command line arguments to a C program I'm writing. I tried posting this in comp.programming yesterday but someone kindly suggested that I'd have better luck here. So here goes! My program ignores any command line arguments, or at least it's supposed to. However, when I pass any command...
8
1854
by: Dawn Minnis | last post by:
Hey guys If I have a program (see codeSnippet1) that I compile to be called test.o Then run it as test.o n n 2 3 4 I want the code to be able to strip out the two characters at the start (always going to be 2) and store them as characters. But I can't seem to get it to work because it is a pointer to a vector of characters. However, if...
2
5865
by: Adam Clauss | last post by:
I am building a GUI to wrap around some of the information/abilities contained within the program netsh. I have figured out how to use redirect the standardinput and standardoutput so that I can read/write from my application. The "easy" way to do this would be to spawn an instance of netsh everytime I need to execute a command, write the...
5
5822
by: jlea | last post by:
I'm trying to pass a filename, obtained with using the fileName property from the OpenFileDialog, as a application parameter in Process.StartInfo.Arguments and run a MFC/C++ application using the Start method. When I hardcode the application parameter such as "/name=c:\\myFile.txt" all is well in the C++ application. When I use the...
5
2902
by: poolshark1691 | last post by:
Just joined and am learning c++, i have got a compiler, i run the executable, i get the DOS command prompt showing me my program but once it gets to the "return 0;" part of the code, basically the end, the prompt disappears, and i miss out on half of my program. A while back someone told me of a line of code to put in that fixes this problem,...
6
6917
by: virgincita schmidtmann | last post by:
Good evening, I would like to pass the size of an array from the commandline. int main(int argc, int *argv) { .... max=*argv; int list; ....
17
3355
by: Matt | last post by:
Hello. I'm having a very strange problem that I would like ot check with you guys. Basically whenever I insert the following line into my programme to output the arguments being passed to the programme: printf("\nCommand line arguement %d: %s.", i , argv ); The porgramme outputs 3 of the command line arguements, then gives a...
0
7518
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7444
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7711
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7954
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7467
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6039
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5085
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3478
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
755
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.