Sunday, April 15, 2012

Quick look at command line: int main(int argc, char* argv[])
#include <iostream>
using namespace std;

int main(int argc,char* argv[]){//argc holds the number of parameter +1 (-d del name = 4 arguments), argv[] holds each character in the array
    int i;
    if (argv[1][0] != '-'){
        cout << "idk what: " << argv[1][0] << " is..."<< endl;
        return -1;
    }
    else{
        cout << argc << endl;
        cout << "i know what that is" <<endl;
        cout <<"Command executed: " <<endl;
        cout << "-------------------------" <<endl;
        cout << " argv[1][0]:" <<endl;
        cout << argv[1][0] << endl;//must use argv[1][x] because argv[0][0] holds the file path name, command prompt accepts a string in the second row([1][x])
        cout << " argv[1][1]:" <<endl;
        cout << argv[1][1] << endl;//gets the second character of the command line
        cout << " argv[1][2]:" <<endl;
        cout << argv[1][2] << endl;//gets the third character of the command line
        cout << " argv[1][3]:" <<endl;
        cout << argv[1][3] << endl;
        cout << " argv[1][4]:" <<endl;
        cout << argv[1][4] << endl;
        cout << " argv[2]:" <<endl;
        cout << argv[2] << endl;//checks 2nd argument
        cout << " argv[3]:" <<endl;
        cout << argv[3] << endl;//checks 3rd argument
        cout << " argv[4]:" <<endl;
        cout << argv[4] << endl;//checks 4th argument
    }
  return 0;
}

No comments:

Post a Comment