我是C编程的新手,我来自Java背景。我想知道为什么在下面的代码中,在while循环中,我必须键入我的输入十次,然后显示所有十个输入。我尝试输入一次,然后立即显示。然后继续输入我的其他输入。帮助while循环在C
#include <stdio.h>
#include <stdlib.h>
#include "Helper.h"
main(){
print(PROGRAM_INFO); //prints program name and author
print(PROMPT);
char input [100]; //array to hold input from user
int isActive = 1; //1 continue shell, 0 terminate shell
int count = 0;
while (isActive == 1 && count < 10){
print(PROMPT);
++count;
scanf("%s", input);
print(input);
}
}
fflush(stdout);工作得很好。谢谢大家 – user69514
是的,与'\ n'相比,fflush肯定是更好的方式。 – LJM
谢谢你帮助我解决了类似的问题,现在我不必再问它了! – Sankofa