I thought I was finished with this program but now I can’t find a way to make it quit. The loop continues even when I enter the terminating character. I’ll post he whole thing. The answer may be simple but I'm just not seeing it.
do{
do{
system("cls");
printf("Enter the name and path of a .TXT file(type 1 to end):\n");
fflush(stdout);
fgets(fname, 128, stdin);
if((s = strchr(fname,'\n')) != NULL) *s = '\0';/* remove newline char */
fp=fopen(fname,"r");
if(fp==NULL)
{
printf("Cannot open file.\n");
system("pause");
continue;
}
else
{
int charctr=0;/*Stores character count*/
while ((c = fgetc(fp)) != EOF)
{
++charctr;/*Chartacter counter*/
}
rewind(fp); /*Takes file back to the begining*/
nlines=linecount(fp);
if (nlines>30)
{
printf("Invalid!!!Lines cannot be more that 30\n\n");
system("pause");
continue;
}
rewind(fp);
avgchar=averagechar(charctr,nlines);
if(avgchar>60)
{
printf("Invalid!!!Average number of characters per line must be less than 60 \n\n");
system("pause");
continue;
}
rewind(fp);
max=longest(fp);
rewind(fp);
min=shortest(fp);
rewind(fp);
w=words(fp);
if(w>500)
{
printf("Invalid!!!Words must be less than 500 \n\n");
system("pause");
continue;
}
break;
rewind(fp);
sentence=sentences(fp);
rewind(fp);
question=percentage(fp,sentence);
rewind(fp);
quote=quotation(fp);
rewind(fp);
fclose(fp);
fp=fopen("summaryData.txt","a");
fprintf(fp,"\n***Filename:%s***\n", fname);/*Print to file*/
fclose(fp);
printf("Enter 1 to quit, 2 to continue>");
scanf("%d",&quit2);
quit = quit2;
}/*end else*/
}while(1);/*Everything is true*/
}while(quit != 1);
return 0;
}