My issue
Problem is not solving it is coming failed in hidden test case
My code
void userFunction() {
FILE *file = fopen("/mnt/codechef/input.txt", "r"); // Open the "input.txt" file for reading
if (file == NULL) {
perror("Error opening file"); // Print an error message if file opening fails
return 1; // Return an error code
}
char buffer[100]; // Buffer to store each line
char *searchWord = "CodeChef"; // The word to search for
int count = 0; // Initialize a counter for occurrences
// Update the code below to solve the problem
while (fgets(buffer,sizeof(buffer), file)!= NULL){
char *found = strstr(buffer,searchWord);
while (found !=NULL){
count++;
found=strstr(found+strlen(searchWord),searchWord);
}
}
printf("Number of occurrences of 'CodeChef': %d\n", count); // Print the total occurrences
fclose(file); // Close the file
}
Learning course: Programming and Problem solving using C
Problem Link: https://www.codechef.com/learn/course/ciet-programming-c/CIETPC37/problems/PPSC278