make sure the factor is valid (also accept non-base 10 numbers)

remotes/1720846149120324653/tmp_refs/heads/master
Jonathan Lamothe 11 years ago
parent 38c1141db4
commit 37b4824a62
  1. 9
      dpu.c

@ -1,3 +1,4 @@
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -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;

Loading…
Cancel
Save