fgets() and gets() works properly for the first time. When I use this function for the second time then I am not asked for the input.
#include<stdio.h>
int main(){
char name[10];
printf("\nEnter your name: ");//Enter Ram Singh Gupti
fgets(name,10,stdin);
printf("\nName using fgets: ");
puts(name);
fflushh(stdin);//what to use instead of fflush since it does not supports in linux
printf("\nEnter your name: ");
gets(name);
printf("\nName using gets: ");
puts(name);
return 0;
}
Input & Output:
My statement
gets(name)
is not taking input. I think it is taking input from the buffer. How can we resolve this issue.
what should I do before gets(name)
to clear the buffer.