In college I was asked if our program detects if the string enter from command line arguments is a integer which it did not(./Program 3.7
). Now I am wondering how I can detect this. So input as for example a
is invalid which atoi detects, but input like for example 3.6
should be invalid but atoi will convert this to an integer.
#include <stdio.h>
int main(int argc, char *argv[]) {
if (argc > 1) {
int number = atoi(argv[1]);
printf("okay\n");
}
}
But offcourse okay should only be printed if argv[1] is really an integer. Hope my question is clear. Many thanks.