jlou is right..
>>C:\Documents and Settings\admin\Desktop>tri2 -3 -4 -5
if these are your arguments, trace back what happens to them.
argc is set to 4. So the first element of argv is tri2. Anyways, below I'm attaching a prog that parses a command line which I wrote not so long ago...here is what it supposed to do...it does have one bug when your command starts out with an alpha char.
Code:
//argument: main 234aa34 34b 23 3b4
//display:
234
34
34
23
3
4
as you can see the prog seperates the integesr from the characters. each time an char or white space is encoutered go to new line.
Code:
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
int main(int argc, char *argv[])
{
int a=0; //counter for amount of letters
char c;
if ( argc == 1 ) { //check for amount of arguments
cout << "\nThere is nothing to parse!\n";
cout << endl;
} else {
for ( int i = 1; i < argc; i++ ) {
for ( int j = 0; j < strlen(argv[i]); j++ ){
c = argv[i][j]; //step through each string and
if ( isdigit(c) ) { //check if value is a digit
if ( a > 0 ) {
cout << endl;
a=0;
}
cout << argv[i][j];// << endl;
}else { a++; } //if value is not digit increment a
}
cout << endl;
}
}
return 0;
}
axon