You are on page 1of 4

Ex No: Delete all repeated words in string

//header file declaration


#include<stdio.h>
#include<string.h>
void main()
{
//variable declaration
char a[100], b[20][20];
int i, j = 0, k=0, n, m;
clrscr();
//get the string until enter is pressed
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;
}
}
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 I Msc SS c programming class, welcome
again
welcome
to
I Msc SS
c
programming
class
,
again
Output:

You might also like