Reputation: 141
I need a hand in terms of processing command line argument (on Windows) in C.
Suppose I have the following situation
C:\Users\USER\Desktop> my_executable arg1 ' "A>200 && B<300 (just some conditions" '
In this case argc = 5
and
C:\Users\USER\Desktop> my_executable arg1 '"A>200 && B<300 (just some conditions"'
In this case argc = 3
Depending on users, the argv and argc will be different. How can I write the code such that the condition and arg1 can be stored correctly :) Required: arg1 is stored into a char pointer condition is also stored into a char pointer
Thanks
Upvotes: 0
Views: 219
Reputation: 43327
Don't use single quotes as argument quotes on Windows unless you want to implement your own argument parser. ^
can be used to escape "
and itself and a few other things. To embed "
in arguments use ""
.
If you really need to, call GetCommandLineW
and parse yourself. GetCommandLineW
returns a string that consists of the executable image name possibly enclosed in double quotes, followed by an optional space and the arguments exactly as given to CreateProcess (which means that ^
processing has already taken place).
Upvotes: 1