2012-06-16 09:12:08 UTC
#include
#include
int main()
{
FILE *inFile;
char filename[64];
printf("\nEnter a file name: ");
gets(filename);
fflush(stdin); /* clear input area so you can pause */
getchar(); /* force the computer to pause until you press a key on the keyboard */
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);
fflush(stdin); /* clear input area so you can pause */
getchar(); /* force the computer to pause until you press a key on the keyboard */
}
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);
}
return 0;