From ce867fb9960f5a007ae130c84ac151b5027b35b1 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Mon, 2 Sep 2013 08:00:10 -0400 Subject: [PATCH] check more carefully that the input file is valid dpu formst --- undpu.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/undpu.c b/undpu.c index 3eed3c2..6cd3ce6 100755 --- a/undpu.c +++ b/undpu.c @@ -3,18 +3,20 @@ #include #include +const char compare_string[] = "DOUBLEPLUS UNZIP, FACTOR="; + int main (int argc, char **argv){ FILE *bob, *joe; - int factor, thing; + int factor, thing, i; char output[FILENAME_MAX]; if((bob = fopen(argv[1],"r"))==NULL){ fputs("That's no input file, THAT'S A SPACE STATION!\n",stderr); return EXIT_FAILURE; } - while(thing != '='){ - thing=fgetc(bob); - if(thing==EOF){ - fputs("You suck! That's not a DPU file!\n",stderr); + for(i = 0; compare_string[i]; i++) { + thing = fgetc(bob); + if(thing != compare_string[i]) { + fputs("You suck! That's not a DPU file!\n", stderr); return EXIT_FAILURE; } }