Return Non Repeating Chars from Array

Ram Pothuraju
This program is to return non-repeating character array from inputted array having repeating characters . 


This program uses the concept of Arrays for the same. And doesnt use built in string functions.
We can modify the same to accept values from the user directly.

#include<stdio.h>
#include<conio.h>
char* removeDuplicates(char arr[]);
void main()
{
 char s[]={'a','b','c','d','e','g','a','b','c','d','e','f'};
 clrscr();
 printf("\nInput Array is: %s\n",s);
 printf("\nOutput Array is: %s\n",removeDuplicates(s));
 getch();
}

char* removeDuplicates(char arr[])
{
 int i=0,j,k;

 while(arr[i]!=0)
 {
 for(j=i+1;arr[j]!=0;j++)
 {
  if(arr[i]==arr[j])
  {
     for(k=j;arr[k]!=0;k++)
   arr[k]=arr[k+1];
     arr[k]='\0';
     j--;
  }
 }
 i++;

 }
 return arr;
}

Tags

Post a Comment

0Comments

Post a Comment (0)