0% found this document useful (0 votes)
26 views4 pages

Delete All Repeated Words in String

This code takes a string as input from the user, splits it on spaces into an array, then removes any repeated words by comparing strings and shifting elements up. It prints the unique words one per line.

Uploaded by

govardhini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views4 pages

Delete All Repeated Words in String

This code takes a string as input from the user, splits it on spaces into an array, then removes any repeated words by comparing strings and shifting elements up. It prints the unique words one per line.

Uploaded by

govardhini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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