#include <stdio.h>
#include <string.h>
int main()
{
char text[]=" pryvitaty z novym rokom i pobazhaty zdaty vsi roboty i otrymaty vysiki baly ";
char *word=text;
char *result;
int n=0;
printf("pryvitaty z novym rokom i pobazhaty zdaty vsi roboty i otrymaty vysoki baly");
printf("\nСлова, які закінчуються буквосполученням 'aty':");
/*
strtok the string to find space
check the last 3 letter,if they match to a,t,y
if yes print word
if no continue loop
*/printf("\n");
result = strtok(word," ");
while(result!= NULL){
//result has the first token??
// printf("String is ---> %s\n",result);
//count od string >=3 ?? ie it has aty as its last char ??
int len=strlen(result);
if (len >2 &&
(result[len-1]=='y' &&
result[len-2]=='t' &&
result[len-3]=='a')
){
n++;
printf("String is ---> %s\n",result);
}
//parse the string further
result = strtok(NULL," ");
}
printf("\n");
printf("\nЇх кількість: %i\n\n",n);
return 0;
}
/*
pryvitaty z novym rokom i pobazhaty zdaty vsi roboty i otrymaty vysoki baly
Слова, які закінчуються буквосполученням 'aty':
String is ---> pryvitaty
String is ---> pobazhaty
String is ---> zdaty
String is ---> otrymaty
Їх кількість: 4
*/
Man page for strtok (on linux ) has good sample prog & explanation of how strtok works.