#include<string.h>
#include<stdio.h>
#include<stdlib.h>
int main()
{
int d;
printf(“enter size of the string\n”);
scanf(“%d”,&d);
char a[100];
char *p;
p = malloc(sizeof(char)*d);
printf(“enter the string\n”);
fflush(stdin);
fgets(p,d,stdin); //didn’t worked with gets(p)?????????
int i,j,count=0,flag=0;
for(i=0;i<=”;i++)
{
for(j=0;j<i;j++)
{
if(*(p+i)==a[j])
{
flag=-1;
}
}
if(flag==0)
{
a[count++]=*(p+i);
}
flag=0;
}
printf(“modified array is \n”);
for(j=0;j<”;j++)
{
printf(“%c”,a[j]);
}
}
Implement the following code before any scanf() or fgets().
int c;
/* discard all characters up to and including newline */
while ((c = getchar()) != ‘\n’ && c != EOF);
Reason: it’s because of the \n stuck in the input stream and we have to flush it out every time.