Как подсчитать строки, слова и ключевые слова в текстовом файле
my task is to count the number of lines, words and keywords present in a text file. i was able to get the lines and the words counted, but i was unable to count the KEYWORDS present in the text file. there are 4 different keywords present in the text. could anyone help me with it. Thanks in advance.
Что я уже пробовал:
#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); }