diff --git a/KNR C/ex1-17.c b/KNR C/ex1-17.c deleted file mode 100644 index 0ad19dd..0000000 --- a/KNR C/ex1-17.c +++ /dev/null @@ -1,73 +0,0 @@ -#include - -void store(); -void enumerate(); -void recall(); -int longest = 0; -int posLongest = 0; - -int main(){ - store(); - enumerate(); - return 0; -} - -void store(){ - - FILE *fp; - fp = fopen("storage.txt", "w"); - - int i = 0; - for(int c = getchar(); c != EOF; c = getchar()){ - fputc(c, fp); - } - fclose(fp); -} - - -//void enumerate() will step through the file and write the value of the -//longest line encountered to int longest and the position (in terms of line -//number) in the file. -void enumerate(){ - - int position = 1; - int length = 0; - - FILE *fp; - fp = fopen ("storage.txt", "r"); - for(int c = fgetc(fp); c != EOF; c = fgetc(fp)) - if(c != '\n'){ - ++length; - continue; - } else if(c == '\n' && length > longest){ - longest = length; - length = 0; - posLongest = position; - ++position; - } else if (c == '\n' && length < longest){ - ++position; - length = 0; - } - fclose (fp); -} - -void recall (){ - FILE *fp; - fp = fopen("storage.txt", "r"); - - int position = 1; - - for(int c = fgetc(fp);; c = fgetc(fp)){ - if(position > posLongest) - break; - - if(c == '\n'){ - ++position; - continue; - } - - if(position == posLongest){ - putchar(c); - } - } -} diff --git a/KNR C/ex1_14_improved.c b/KNR C/ex1_14_improved.c index b088d37..c3fef24 100644 --- a/KNR C/ex1_14_improved.c +++ b/KNR C/ex1_14_improved.c @@ -1,11 +1,9 @@ #include - /*Initial implementation of KNR C Exercise 1-14*/ int main(){ - /*Initialize an array of labels for the numerical table later. This looks - * wierd since it's mostly refTable[] again, but again, we do this at + /*Initialize an array of labels for the numerical table later. Done at * copile rather than procedurally in order to avoid adding an extra if * statement on the print loop to look for the specific case where i is * 0 or 27 and print a different character that isn't in refTable*/ diff --git a/KNR C/ex1_16.c b/KNR C/ex1_16.c index 19cea6a..a028a38 100644 --- a/KNR C/ex1_16.c +++ b/KNR C/ex1_16.c @@ -23,7 +23,7 @@ int main(){ //statement to set value as in original code. char line[MAXLINE]; //Initialize array for storing current line. - char longest [MAXLINE]; //Initialize array for storing longest line so far. + char longest[MAXLINE]; //Initialize array for storing longest line so far. while ((currentLength = pullLine(line, MAXLINE)) > 0){ if (currentLength > max){