I am trying to take 2 parameters from the cmd line in C. The second number must not be higher than 100. However, when running the program with 23 405, it executes without any errors.
int main(int argc, char * argv[]){
char *inputs;
int input1= strtol(argv[1], &inputs, 10);
int input2= strtol(argv[2], &inputs, 10);
if ((*inputs!='\0') || (argc < 3) || (input1 > 1) || (input2 >= 100)
|| (input1 >= input2))
{
printf("Error.");
return 1}
return 0;
}
I am new to C so any help is greatly appreciated!
Aucun commentaire:
Enregistrer un commentaire