From 37b4824a62065571ecf8dee3015bb97c8b17932d Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Fri, 23 Aug 2013 13:07:31 -0400 Subject: [PATCH] make sure the factor is valid (also accept non-base 10 numbers) --- dpu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dpu.c b/dpu.c index aa6fc80..d699d85 100755 --- a/dpu.c +++ b/dpu.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -7,7 +8,13 @@ int main (int argc, char **argv){ FILE *bob,*joe,*moe; int thing, factor, arg; if(argc >= 3){ - factor = atoi (argv[1]); + char *end_char; + factor = strtol(argv[1], &end_char, 0); + if(!*(argv[1]) || *end_char) + { + fputs("I can haz number?\n", stderr); + return EXIT_FAILURE; + } arg = 2; }else{ factor = 9;