storage.txt is now created at runtime rather than being assumed to be present and empty. recall() now removes storage.txt at completion. main() now includes a check to see whether storage.txt already exists, sends an error message, and exits with code 1 if storage.txt is already present.
This commit is contained in:
parent
5ec722b2ca
commit
481f76699e
1 changed files with 16 additions and 8 deletions
|
|
@ -1,4 +1,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void store();
|
||||
void enumerate();
|
||||
|
|
@ -7,6 +9,11 @@ int longest = 0;
|
|||
int posLongest = 0;
|
||||
|
||||
int main(){
|
||||
if((access("storage.txt",F_OK)) == 0){
|
||||
printf("Error: storage file already exists.");
|
||||
return 1;
|
||||
EXIT_FAILURE;
|
||||
}
|
||||
store();
|
||||
enumerate();
|
||||
recall();
|
||||
|
|
@ -40,14 +47,14 @@ void enumerate(){
|
|||
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;
|
||||
} else if(c == '\n' && length > longest){
|
||||
longest = length;
|
||||
length = 0;
|
||||
posLongest = position;
|
||||
++position;
|
||||
} else if (c == '\n' && length < longest){
|
||||
++position;
|
||||
length = 0;
|
||||
}
|
||||
fclose (fp);
|
||||
}
|
||||
|
|
@ -72,4 +79,5 @@ void recall (){
|
|||
}
|
||||
}
|
||||
fclose (fp);
|
||||
remove("storage.txt");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue