How to print the words ending with letter s in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
  
void PrintWordsEndingWithS(char str[], char* delimiter) {
    char* word = strtok(str, delimiter);
  
    while (word != NULL) {
        if (word[strlen(word) - 1] == 's') {
            puts(word);
        }
        word = strtok(NULL, delimiter);
    }
}
  
int main(void)
{
    char s[] = "c lens c++ news java chess";
  
    PrintWordsEndingWithS(s, " ");
  
    return 0;
}
  
  
  
  
  
/*
run:
  
lens
news
chess
  
*/

 



answered Jan 4, 2024 by avibootz
edited Jan 5, 2024 by avibootz
...