Thursday, 24 January 2013

Removing duplicacy in a string with C


#include<stdio.h>
#include<conio.h>
void main()
{
char a[10];
char x;
int i,j,k;
clrscr();
printf("enter a string:");
scanf("%s",&a);

for(j=0;j<10;j++)
{
x=a[j];
for(i=j+1;i<10;i++)
{
if(a[i]==x)
{
//printf("%d",i);

for( k=i;k<10;k++)
{
a[k]=a[k+1];

}
}
}
}
printf("%s",a);
getch();
}

input: microsoftim
ouptut: microsft

No comments:

Post a Comment