我的主要问题是为什么 fflush(stdin); 功能不工作?每当我运行代码时,我都无法使用空格 ex 获得第二个输入。你好世界,但我得到你好??谢谢
#include <stdio.h>
main(){
int x;
double y;
char string[100];
/*
* string input
*/
printf("Enter one word: ");
scanf("%s", string); // note there is no & before string */
printf("The word you entered was >>%s<<\n");
printf("Enter many words: ");
fflush(stdin); // <---- for some reason this function is not working
scanf("%[^\n]", string); // read up to a newline (multiple words)
printf("The text you entered was >>%s<<\n");
getchar();
}