have to prompt the user for file and then count words, characters and lines.
I can get the prompt to ask for the file, but nothing after that. Please help. Also, I know the fflush i bad form, but it's what the professor asked us to use.
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *inFile;
char filename[64];
printf("\nEnter a file name: ");
gets(filename);
fflush(stdin);
getchar();
inFile = fopen(filename, "r");
if(inFile == NULL)
{
printf("\nThe File %s was not successfully opened.", filename);
printf("\nPlease check that the file currently exists. \n");
return(1);
}
int countword = 0;
int countchar = 0;
int linecount = 0;
int count = 0;
char c;
c = getc(inFile);
while (c != EOF );
{
countchar++;
if (c == '\n') linecount++;
if (c == ' ') countword++;
c = getc(inFile);
}
fclose (inFile);
if (countchar != 0);
{
printf("Number of characters = %d, number of lines = %d, Number of words%d\n", countchar, linecount, countword);
}
fflush(stdin);
getchar();