Saturday 11 November 2017

C Program to Print the Words Ending with Letter S


Code:

#include
#include

char str[100];

void main()
{
    int i, t, j, len;

    printf("Enter a string : ");
    scanf("%[^\n]s", str);

    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++)
                printf("%c", str[j]);
            t = i + 1;
            printf("\n");
        }
        else
        {
            if (str[i] == ' ')
            {
                t = i + 1;
            }
        }
    }
}

Output:

Enter a string : Welcome to ExecuteCodes C Programming Class, Welcome Again to C Class !
ExexuteCodes
Class



More C Programs:












100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...