I am looking to compare a users input to an integer once they enter some type whether that be a string or float etc. into the command line. If the input is not an integer, i want to produce an error message. I have tried using isdigit()
and if(atoi(argv[i])>=0)
but have had no luck. How do i go about doing this? Thanks in advance.
if( argc != 4 )
{
printf("invalid.\n");
error();
}
else if(atoi(argv[1]) >= 1 && atoi(argv[2]) >= 1 && atoi(argv[3]) >= 0){
N = atoi(argv[1]);
M = atoi(argv[2]);
seed = atoi(argv[3]);
mult(N,M,mat1,mat2,seed);
}
else
{
printf("invalid argument.\n");
error();
}
command line input:
$./filename 1 2 e
this still runs my program but i want it to exit when there's a non integer input.