diff --git a/literate/Muri.md b/literate/Muri.md index f9cbb61..403e158 100644 --- a/literate/Muri.md +++ b/literate/Muri.md @@ -244,10 +244,12 @@ part of pass1()). ~~~ void pass2(char *fname) { - char *buffer = (char *)source; + char *buffer; FILE *fp; + int inBlock; + inBlock = 0; + buffer = (char *)source; here = 0; - int inBlock = 0; fp = fopen(fname, "r"); while (!feof(fp)) { read_line(fp, buffer); diff --git a/literate/Unu.md b/literate/Unu.md index 7b7cca3..edcf6a6 100644 --- a/literate/Unu.md +++ b/literate/Unu.md @@ -29,14 +29,16 @@ I use this for readability purposes. ~~~ void read_line(FILE *file, char *line_buffer) { + int ch, count; + if (file == NULL || line_buffer == NULL) { printf("Error: file or line buffer pointer is null."); exit(1); } - int ch = getc(file); - int count = 0; + ch = getc(file); + count = 0; while ((ch != '\n') && (ch != EOF)) { line_buffer[count] = ch; diff --git a/tools/muri.c b/tools/muri.c index 94e3c9a..2fdb5d7 100644 --- a/tools/muri.c +++ b/tools/muri.c @@ -126,10 +126,12 @@ void pass1(char *fname) { fclose(fp); } void pass2(char *fname) { - char *buffer = (char *)source; + char *buffer; FILE *fp; + int inBlock; + inBlock = 0; + buffer = (char *)source; here = 0; - int inBlock = 0; fp = fopen(fname, "r"); while (!feof(fp)) { read_line(fp, buffer); diff --git a/tools/unu.c b/tools/unu.c index 2ace731..7d954d6 100644 --- a/tools/unu.c +++ b/tools/unu.c @@ -4,13 +4,14 @@ #include #define KiB * 1024 void read_line(FILE *file, char *line_buffer) { + int ch, count; if (file == NULL || line_buffer == NULL) { printf("Error: file or line buffer pointer is null."); exit(1); } - int ch = getc(file); - int count = 0; + ch = getc(file); + count = 0; while ((ch != '\n') && (ch != EOF)) { line_buffer[count] = ch; count++;