Browse Source

Improve int argument parsing

masstesting
Adam Goldsmith 6 years ago
parent
commit
0b947b701f
  1. 13
      csim.c

13
csim.c

@ -17,11 +17,14 @@ void print_usage() @@ -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[])