#include <stdio.h>
#include <string.h>
int countOccurrences(const char* s, const char* word) {
int count = 0;
const char* temp = s;
while ((temp = strstr(temp, word)) != NULL) {
count++;
temp += strlen(word);
}
return count;
}
int main() {
const char* s = "cprogramming cprogramming c++ c# c++ cprogramming c# cprogramming";
const char* word = "cprogramming";
printf("Occurrences of '%s': %d\n", word, countOccurrences(s, word));
return 0;
}
/*
run:
Occurrences of 'cprogramming': 4
*/