I am writing a program that would allow a user to input the name of the file they wish to open. I have added in there an option to enter a specific character ("Q" in this instance) to return to the previous menu (which I believe I have working properly).
I am running into a little hiccup, whenever, I enter "1", it will return me to the previous menu.
Below is the function:
Code:
ppr *readPPRForm(ppr *L){
ppr *new = malloc(sizeof(ppr));
char fileName[50];
FILE *inFile = NULL;
do{
printf("Please enter the name of the file you wish to read (type Q to return): ");
fgets(fileName, sizeof(fileName), stdin);
removeNL(fileName);
if (((fileName[0] = 'q') || (fileName[0] == 'Q')) && (fileName[1] =='\0')){
return 0;
}
inFile = fopen(fileName, "r");
if (inFile == NULL){
printf("Could not open %s file for reading.\n", fileName);
}
} while (inFile == NULL);
fclose(inFile);
return new;
}
Here is what the output looks like when I compile and test run it:
Code:
***********************************
PPR DATABASE FOR ORBI
***********************************
-----------------------------------
|****SELECT FROM THE FOLLOWING****|
| 1) Input New PPR Request |
| 2) Read External PPR Form |
| 3) Lookup Existing PPR Request |
| 4) Quit |
-----------------------------------
Option: 2
Please enter the name of the file you wish to read (type Q to return): q
-----------------------------------
|****SELECT FROM THE FOLLOWING****|
| 1) Input New PPR Request |
| 2) Read External PPR Form |
| 3) Lookup Existing PPR Request |
| 4) Quit |
-----------------------------------
Option: 2
Please enter the name of the file you wish to read (type Q to return): 1
-----------------------------------
|****SELECT FROM THE FOLLOWING****|
| 1) Input New PPR Request |
| 2) Read External PPR Form |
| 3) Lookup Existing PPR Request |
| 4) Quit |
-----------------------------------
Option: 4