At college, I was asked if our program showed whether a string from the command line arguments entered an integer that was not ( ./Program 3.7). Now I wonder how I can detect this. Thus, an input, for example, is ainvalid that atoi detects, but an input, such as, for example 3.6, must be invalid, but atoi converts 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 indeed an integer. Hope my question is clear. Many thanks.
source
share