C/C++ >> Seperating strings from the command line
Posted by fsvara on 13:32:00 03-03-2002
Well, check my "Base64 encoder" I submitted, you'll notice it has a problem - any number of any kind of whitespace in a row is treated as one space.
That is because the string gets split up in argv[], and i put it together again, using spaces to seperate them.
There's no way to know how many spaces were used on the command line, or if it was a tab.

Any ideas?
Posted by fsvara on 15:05:00 03-03-2002
ok, i just found out simply putting quotes around text will pass the stuff within the quotes to the program as only one parameter in argv.

thanks to robert

[ This Message was edited by: fsvara on 2002-03-03 15:06 ]
Posted by KaGez on 07:19:00 03-04-2002
another easy method would be to scan for the ASCII values of spaces or tabs
[addsig]
Posted by fsvara on 12:33:00 03-04-2002
not really.
when you start a program with arguments, the shell (?) uses the whitespaces between arguments to seperate them, puts the actual words into an array and gives them to main.

the whitespaces the user typed on the shell are not there anymore.
Posted by KaGez on 07:37:00 03-05-2002
oh, then it's even easier.
Just use sprintff and build up the string like you'd have it, for example:

sprintf(string, "%s %s", string1, string2);

instead of "stringX" you just use the argv[x] and you'll have the string
[addsig]
Posted by fsvara on 15:07:00 03-05-2002
gah, just read what i actually posted!

i am doing that already. but users can seperate strings with more than one space on the commandline, or with tabs, or whatever.
These whitespace characters will be lost, and you can't say with certainity the parameters were speerated with one space only! How to do that was what I was actually asking.
Posted by KaGez on 00:36:00 03-06-2002
erm...
how the hell would you use in the command line ?! In DOS it might do some strange stuff, but in most other shells you'll get a filename completion when you press
[addsig]
Posted by Fortuno on 01:50:00 03-06-2002
KaGez: You could use CTRL-V Tab ... and if they seperated the arguments with multiple spaces, all but one would be lost..
Posted by fsvara on 14:14:00 03-06-2002
i meant tab just an example for "some whitespace". anyway, it doesn't matter as there's the same problem when you seperate the arguments with more than one space.