I'm having some problems running the following code. If I provide more than five characters of input to the scanf
method feeding array a
, the rest of the characters go into array b
and I don't get to provide input again. I tried using fflush()
, but it didn't help. What's going on, and how can I fix it?
#include<stdio.h>
int main()
{
char a[6];
char b[20];
printf("Enter any string :\n");
scanf("%5s",a);
printf("%s\n",a);
fflush(stdin);
scanf("%s",b);
printf("%s\n",b);
return 0;
}