Discussion:
Path as argument to c programme
(too old to reply)
atmkoh
2010-01-04 17:12:56 UTC
Permalink
I generally use Visual Basic both vb6 and dot net variants. Now I am
using console visual c.
The problem is that I need to get an argument from the user as to the
working directory such as "E:\work\project\data"

In c we have to use "E:\\WORK\\project\\data"

How to I append the extra "\" to the string?

Seasons Greetings and Best regards

Andrew
Victor Bazarov
2010-01-04 17:30:44 UTC
Permalink
Post by atmkoh
I generally use Visual Basic both vb6 and dot net variants. Now I am
using console visual c.
The problem is that I need to get an argument from the user as to the
working directory such as "E:\work\project\data"
OK
Post by atmkoh
In c we have to use "E:\\WORK\\project\\data"
Only if it's inside the C program and is the actual string literal. If
it's an argument coming from a file or the command line, we don't have
to double the backslashes.
Post by atmkoh
How to I append the extra "\" to the string?
Where? Try without appending the extra \.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Igor Tandetnik
2010-01-04 17:29:33 UTC
Permalink
Post by atmkoh
I generally use Visual Basic both vb6 and dot net variants. Now I am
using console visual c.
The problem is that I need to get an argument from the user as to the
working directory such as "E:\work\project\data"
In c we have to use "E:\\WORK\\project\\data"
How to I append the extra "\" to the string?
You only need to write extra \ in string literals, because otherwise it's interpreted as an escape character. E.g. "\n" is a string containing a single line-feed character, while "\\n" is a string containing two characters, backslash and 'n'.

In user-entered data, or generally in strings that are generated programmatically, you don't need to double backslashes.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
Loading...