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 parse_int_arg(char* arg)
|
||||||
{
|
{
|
||||||
int i = atoi(arg);
|
char* end;
|
||||||
if (i != 0)
|
int i = strtol(arg, &end, 0);
|
||||||
return i;
|
if (!i || *end != '\0')
|
||||||
else
|
{
|
||||||
exit(-1);
|
printf("Invalid argument \"%s\"\n", arg);
|
||||||
|
print_usage();
|
||||||
|
}
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
|
Reference in New Issue
Block a user