C Program to remove repeated characters from a String

C Program to remove repeated characters from a String  . Compiled in Dev C++

#include<stdio.h>
#include<string.h>
#include<conio.h>
void printFirstChar(char [],char []);
int checkifExist(char ,char *);
main()
{
       char text[50],target[50];
      
      
       printf("\nProgram to remove repeated  characters from a String \n");
       printf("\n------------------------------------------------------------------\n\n\n");
       printf("Enter Text : ");                                                   
       gets(text);  
       printFirstChar(text,target);
       
       printf("\n\New Word after removing repeated  Characters is  : %s" ,target);
        
    
       getch();
               
      
}


 void printFirstChar(char a[],char b[])
     {
        char *p;
        int i,isExits,pos=0;
        for(i=0;i<strlen(a);i++)
        {
            p=&a[i];
            isExits=checkifExist(*p,b);
            if(isExits==0) 
            { 
               b[pos]=*p;
               pos++;
            }                 
                                  
        } 
        
        b[pos]='\0';
        
        
     }
        
        
      int checkifExist(char k,char *b)
      {
          while(*b!='\0')
          {
            if(*b==k)
            {
              return 1;
              break;         
            }
                          
           b++;
           
          }
          
          return 0;
          
      }

Output

removerepitation

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s