Return Non Repeating Chars from Array

This program is to return non-repeating character array from inputted array having repeating characters . This is a part of Mumbai University MCA Colleges C Programs MCA Sem 1

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;
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

No comments:

Post a Comment