fflush(stdin)
との使用の違いは何flushstdin()
ですか? 私が知っている唯一の違いは、を使用する前にその void を記述する必要があることですが、そのflushstdin()
理由はわかりません。
void flushstdin()
{
int c;
while((c = getchar()) != '\n' && c != EOF);
}
int main () {
float a, b, c;
float s=0, ar1=0, ar2=0;
printf("Inform value of side A");
while(scanf("%f",&a) != 1 || a <= 0){
printf("Invalid value.\n");
flushstdin();
}
}
と
int main(){
float a,b,c,s=0;
printf("Inform value of side A.");
while(scanf("%f",&a) != 1 || a<=0){
printf("Invalid value.\n");
fflush(stdin);
}
}
私は初心者です!どのコードが最適ですか? それとも等しいですか?