This code basically returns an unique string. So, the resultant string only has unique characters.
Input: "This is an example input" Output: "this anexmpl" . But i should be getting a 'u' as well. It was working fine with other IDEs. I just downloaded devcpp 4.9.9.2 and I am using it as an IDE. The code works fine.
#include<stdio.h>
#include<conio.h>
#include<string.h>
int search(char result[30],char temp)
{
for(int i=0;result[i];i++){
if(temp == result[i])
return 0;
}
return 1;
}
int main()
{
char str[20];
printf("\nEnter String: ");
gets(str);
//scanf("%[^\t\n]s",str);
//strlwr(str);
for(int i=0;i<strlen(str);i++){
if(str[i]>=65 && str[i]<=90)
str[i]=str[i]+32;
}
int length=0;
for(int i=0;str[i];i++)
length++;
char result[30];
result[0]='\0';
int ctr=0;
for(int j=0;str[j];j++){
if(search(result,str[j]) == 1){
printf("%c\t",str[j]);
result[ctr]=str[j];
ctr++;
}
}
result[ctr]='\0';
printf("\nUnique String:");
printf("\n%s\n",result);
char reverse[20];
int reslength=0;
for(int k=0;result[k];k++)
reslength++;
int counter=0;
printf("Reversed String:\n");
for(int t=reslength-1;t>=0;t--){
printf("%c",result[t]);
}
getch();
return 0;
}