Using fgets after scanf [duplicate]
问题 This question already has answers here : fgets doesn't work after scanf [duplicate] (9 answers) Closed 18 days ago . I want to get rid of buffer overflow and I am using fgets instead of scanf to limit the characters. But whenever I enter something with scanf before fgets , it doesn't work correctly anymore. This code works correctly #include <stdio.h> int main() { char name[10]; printf("Who are you? \n"); fgets(name,10,stdin); printf("Good to meet you, %s.\n",name); return(0); } This code