Improve int argument parsing
This commit is contained in:
parent
70b79a8b56
commit
0b947b701f
13
csim.c
13
csim.c
@ -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[])
|
||||
|
Reference in New Issue
Block a user