d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Commandlineargument/char Array C
Add Reply New Topic New Poll
Member
Posts: 20,928
Joined: Mar 18 2009
Gold: 435,910.13
Sep 20 2013 06:54pm
Code
int main(int argc, char *argv[]){
bool inpVal;
inpVal = checkIfValid(argc, *argv);
}

bool checkIfValid(int clength, char argv[]){
if((clength <= 1) || (clength > 2)){
printf("Invalid Input: Please enter exactly 1 number as a command line argument.\n");
return false;
}

else if(atoi(argv[1]) < 0){
printf("Invalid Input: Please enter non-negative number.\n");
return false;
}


2 questions
1. what is the "*" before argv signify?
2. why does the compiled exe stop working if i get to the else if block? basically i would like to check if the
command line argument is negative and return false if it is

new to c appreciate it if someone would explain this to me
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 20 2013 06:57pm
Quote (bakalolo @ Sep 20 2013 08:54pm)
Code
int main(int argc, char *argv[]){
      bool inpVal;
      inpVal = checkIfValid(argc, *argv);
}

bool checkIfValid(int clength, char argv[]){
  if((clength <= 1) || (clength > 2)){
      printf("Invalid Input: Please enter exactly 1 number as a command line argument.\n");
      return false;
  }
 
  else if(atoi(argv[1]) < 0){
      printf("Invalid Input: Please enter non-negative number.\n");
      return false;
  }


2 questions
1. what is the "*" before argv signify?
2. why does the compiled exe stop working if i get to the else if block? basically i would like to check if the
command line argument is negative and return false if it is

new to c appreciate it if someone would explain this to me


Google pointers. read tutorials and practice.
Member
Posts: 20,928
Joined: Mar 18 2009
Gold: 435,910.13
Sep 20 2013 07:31pm
nm fixed it

This post was edited by bakalolo on Sep 20 2013 07:41pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll