fgets

Using fgets after scanf [duplicate]

寵の児 提交于 2021-01-10 03:35:23
问题 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

Using fgets after scanf [duplicate]

别等时光非礼了梦想. 提交于 2021-01-10 03:30:18
问题 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

Using fgets after scanf [duplicate]

*爱你&永不变心* 提交于 2021-01-10 03:29:25
问题 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