#include <stdio.h>
#include <string.h>
int CountWordsEndingWithSOrY(char str[], char* delimiter) {
char* word = strtok(str, delimiter);
int count = 0;
while (word != NULL) {
if (word[strlen(word) - 1] == 's' || word[strlen(word) - 1] == 'y') {
count++;
}
word = strtok(NULL, delimiter);
}
return count;
}
int main(void)
{
char s[] = "c lens c++ news java enjoy chess c# money";
printf("%d", CountWordsEndingWithSOrY(s, " "));
return 0;
}
/*
run:
5
*/