Quote:
but i was unable to count the KEYWORDS present in the text file
The problem here is that you didn't try to do the count.
Try to read this as a file and see how many words it find:
First
Second-third
Fourth fifth
There is a surprise. :)
Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
#include <stdio.h>
int main()
{
FILE *fp;
char filename[100];
char ch;
int linecount, wordcount;
linecount = 0;
wordcount = 0;
printf("Enter a filename :");
gets(filename);
fp = fopen(filename,"r");
if ( fp )
{
while ((ch=getc(fp)) != EOF) {
if (ch == ' ' || ch == '\n') { ++wordcount; }
if (ch == '\n') { ++linecount; }
}
if (wordcount > 0) {
++linecount;
++wordcount;
}
}
else
{
printf("failed to open the file\n");
}
printf("Lines : %d \n", linecount);
printf("Words : %d \n", wordcount);
return(0);
}
Indentation style - Wikipedia[
^]
Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[
^]
ultraedit[
^]