I am a new learner of C and I tried to write a program about searching a keywrod from a .txt file and counting the number of time that the keyword repeats

My program is below...it can't work...and I can't understand why....
can someone please help me...T_T
Thank you

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void)
{
	FILE *fptr;
	fptr=fopen("composition.txt","r");
    int cnt_keyword=0;
    char word[80];
    char keyword[80];

    printf("Enter the word you want to search for:");
    scanf("%s",&keyword);

while (fscanf(fptr, "%80s", word) != EOF)
 {
        if (strcasecmp(word, keyword) == 0)
         {
             ++cnt_keyword;
        }
 }

printf("No. of keyword: %d",cnt_keyword);
system("pause");
}

Recommended Answers

All 2 Replies

I am a new learner of C and I tried to write a program about searching a keywrod from a .txt file and counting the number of time that the keyword repeats

My program is below...it can't work...and I can't understand why....
can someone please help me...T_T
Thank you

Why can't it work? What does it do? Are you sure you are reading the file properly? Try displaying the words are you read them to see if they are correct.

I am extremely sorry...
There must be something wrong to my Dev-C++..
becasue I also can't run other's program just now
After reinstalling my Dev C++..
It turns out that the program can be run
Sorry for wasting everyone's time....Orz

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.