This is a C Program to print the words ending with letter s.
This program takes a string as input and print the words ending with letter s.
1. Take a string as input.
2. Find the blank space in the string and then check if the previous letter is ‘s’ or not.
3. If it is ‘s’ then print the corresponding word.
Here is source code of the C Program to print the words ending with letter s. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
* C Program to Print the Words Ending with Letter S
int i, t, j, len;
printf("Enter a string : ");
len = strlen(str);
str[len] = ' ';
for (t = 0, i = 0; i < strlen(str); i++)
if ((str[i] == ' ') && (str[i - 1] == 's'))
for (j = t; j < i; j++)
t = i + 1;
if (str[i] == ' ')
t = i + 1;
1. Take a string as input and store it in the array str.
2. Find its length and add a blank space to the input string at last.
3. Using for loop find the blank space in the string and check whether its previous letter is ‘s’ or not.
4. If it is ‘s’ then print the corresponding word. Otherwise repeat the steps 3-4 until the last element of the string.
Enter a string : Welcome to Sanfoundry's C Programming Class, Welcome Again to C Class ! Sanfoundry's Class
Sanfoundry Global Education & Learning Series – 1000 C Programs.