Write a program that will tell the user how many characters and how many lines a file contains. You may assume that each line is no more than 1000 characters long.
To do this program:
Also display the number of words in the file.
For our purposes, a word is a sequence of alphanumeric characters separated by one or more spaces. A space is any whitespace character: space, tab ('\t'), or newline ('\n'). The ctype.h header file contains a function called isalnum(c) that will tell you if the given character is alphanumeric. And there is a function called isspace(c) that will tell you if the given character is a whitespace.
CountWord.c:
#include <stdio.h>
#include <string.h>
int main ( void )
{
char file_name[100];
int lineCount,
j,numWord=0,numChar=0,totalChar=0,totalWords=0;
char array[1000];
char line[1000];
char ch;
printf("Enter the file name: ");
scanf("%s", file_name);
FILE *file = fopen ( file_name, "r"
);
if ( file != NULL )
{
lineCount=0;
while ( fgets ( line,
sizeof line, file ) != NULL ) /* read a line */
{
strcpy(array, line);
for(j=0; j<strlen(array); j++)
{
ch = array[j];
if(isalnum(ch)||isspace(ch))
numChar++;
if (isspace(ch))
numWord++;
}
lineCount++;
}
printf("Number of Lines:
%d\n",lineCount);
printf("Number of Words:
%d\n",numWord);
printf("Number of
Characters: %d\n",numChar);
fclose ( file );
}
else
{
perror ( file_name ); /*
why didn't the file open? */
}
return 0;
}
output:

Write a program that will tell the user how many characters and how many lines a...