P
parjit
I have written a simple utility which will take the command line
string and parse it for command line parameters.
It's almost completely working. What I have is about 3 basic
parameters, then one that takes 2 sub input characters, and finally,
another to allow a filename or such.
This is just for practice.
For example, typing filename.exe -a -b
Will just print "letter a" and "letter b". I also have another option
for -n1 and -n2 to print something like "node 1" and "node 2".
Anyway, all that is peachy.
My problem is that I want another option to take a parameter like:
-f filename.txt
And print that back to the screen. For example:
filename.exe -a -b -n2 -f anything.txt
Should print:
letter a
letter b
node 2
anything.txt
But it doesn't. The anything.txt won't work. Basically, what I did in
my source is have an if statement to read argv[0] for a / or -,
then a switch and case statement to read the letters. No problem.
Later, I have:
case 'f' : if(argv[2] == ' ')
So if the character after "f" is a space, it will know the filename is
the next variable. Here's what I have:
argv++;
printf("%s", argv);
It compiles fine. But if I type:
filename.exe -f anything.txt
It will not display it "anything.txt". I have no idea whats wrong.
I'm not looking for anything to write this for me, since I prefer to
program it out on my own. Can anybody give me some suggestions?
string and parse it for command line parameters.
It's almost completely working. What I have is about 3 basic
parameters, then one that takes 2 sub input characters, and finally,
another to allow a filename or such.
This is just for practice.
For example, typing filename.exe -a -b
Will just print "letter a" and "letter b". I also have another option
for -n1 and -n2 to print something like "node 1" and "node 2".
Anyway, all that is peachy.
My problem is that I want another option to take a parameter like:
-f filename.txt
And print that back to the screen. For example:
filename.exe -a -b -n2 -f anything.txt
Should print:
letter a
letter b
node 2
anything.txt
But it doesn't. The anything.txt won't work. Basically, what I did in
my source is have an if statement to read argv[0] for a / or -,
then a switch and case statement to read the letters. No problem.
Later, I have:
case 'f' : if(argv[2] == ' ')
So if the character after "f" is a space, it will know the filename is
the next variable. Here's what I have:
argv++;
printf("%s", argv);
It compiles fine. But if I type:
filename.exe -f anything.txt
It will not display it "anything.txt". I have no idea whats wrong.
I'm not looking for anything to write this for me, since I prefer to
program it out on my own. Can anybody give me some suggestions?