I want to input a file into an array, and if the file doesn't exist, the program exits. I have a lot of stuff to input from the command line, and if I make a typo the program exits and I have to enter it all again. How can I create an error message that keeps the program running, and lets me retry typing the file name right.
FILE *fp;
char filename[100];
puts("Enter the phrase file: ");
scanf("%s", filename);
fp = fopen(filename, "rb");
I know I have to do an if (fp==Null)
type thing, I just don't know how to loop back around to let me try again.
For some reason, this won't work:
FILE *fp;
FILE *sheep;
char filename[100];
do
{
puts("Enter the phrase file: ");
scanf("%s", filename);
fp = fopen(filename, "rb");
}
while (fp == NULL);