I'm trying to write a simple program that takes 1 and only 1 commandline argument, and it must be an integer. I couldn't find a function to help me, the only one I found, atoi, returned 3 if the argument was 3dddf (which is just dumb, IMHO).
I decided to write my own function, and it looks like so:
int CmdlineConverter(char * arg)
int i = 0;
while (arg[i] != NULL)
if (isdigit((int) arg[i]) != 0)
Then, in main, I call this function as CmdlineConverter(argv) and check to make sure it is not == NULL before continuing.
If I am correct, my code above checks to make sure that the argument is all digits, in which case it returns the number, or it returns NULL. It seems to work, except when the argument is zero. The isdigit returns OK, so I know it recognizes zero as a digit. It was my understanding that in C, zero and NULL are different values, but if I have return(0) instead of return atoi(arg), my IF (cmdlineconverter == NULL) code gets executed.
What the heck am I doing wrong?