Improve int argument parsing

This commit is contained in:
Adam Goldsmith 2016-04-26 10:22:34 -04:00
parent 70b79a8b56
commit 0b947b701f

13
csim.c
View File

@ -17,11 +17,14 @@ void print_usage()
int parse_int_arg(char* arg)
{
int i = atoi(arg);
if (i != 0)
return i;
else
exit(-1);
char* end;
int i = strtol(arg, &end, 0);
if (!i || *end != '\0')
{
printf("Invalid argument \"%s\"\n", arg);
print_usage();
}
return i;
}
int main(int argc, char* argv[])