Also close bug
[filters.git] / scramble.c
index 978e06e8d877910afbccd7969127322b9e35ecaf..c1e989a2dcd862223b3fa054608b71df0e905a4d 100644 (file)
@@ -23,7 +23,7 @@
 #include <string.h> // for strlen()
 #include <time.h> // for time()
 
-#define ALLOW_FILE_IO 1
+#define ALLOW_FILE_IO 0
 
 
 /* strips 'reduction' characters from the end of the input string and returns the result
@@ -120,7 +120,7 @@ char *clear_string(char *string) {
 
 int main(int argc, char **argv) {
   int word_length;
-  char c, tempchar, *word;
+  char c, tempchar, *word, *rword;
   FILE *infile, *outfile;
   
 #if ALLOW_FILE_IO
@@ -171,13 +171,20 @@ int main(int argc, char **argv) {
   c = fgetc(infile);
   
   if(feof(infile)) {
-    printf("Reached EOF while reading the first character of the input file!\n");
+    fprintf(stderr, "Reached EOF while reading the first character of the input file!\n");
+    free(word);
     return 4;
   }
   
   while(!feof(infile)) {
     if(isalpha(c)) {
-      word = realloc(word, word_length+2); // one for the new character, one for the null
+      rword = realloc(word, word_length+2); // one for the new character, one for the null
+      if(rword == NULL){
+        free(word);
+        fprintf(stderr, "Unable to allocate memory\n");
+        return 5;
+      }
+      word = rword;
       word[word_length] = c;
       word[word_length + 1] = '\0'; // duplicate addition with the next line, but possibly more readable
       word_length++;
This page took 0.009485 seconds and 4 git commands to generate.