Saturday 11 November 2017

C Program to Delete All Repeated Words in String


Code:

#include
#include

void main()
{
    char a[100], b[20][20];
    int i, j = 0, k = 0, n, m;

    printf("enter the string\n");
    scanf("%[^\n]s", a);
    for (i = 0;a[i] != '\0';i++)
    {
        if (a[i] == ' ')
        {
            b[k][j] = '\0';
            k++;
            j = 0;
        }
        else
        {
            b[k][j] = a[i];
            j++;
        }
    }
    b[k][j] = '\0';
    for (i = 0;i <= k;i++)
    {
        for (j = i + 1;j <= k;j++)
        {
            if (strcmp(b[i], b[j]) == 0)
            {
                for (m = j;m <= k;m++)
                    strcpy(b[m], b[m + 1]);
                k--;
            }
        }
    }
    for (n = 0;n <= k;n++)
    {
        printf("%s\n", b[n]);
    }
}

Output:

enter the string
welcome to executecodes c programming class ,  welcome again to c class !
welcome
to
executecodes
c
programming
class

again
!

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...