dimanche 19 avril 2015

c language scanf - fflush(stdin) - doesnt work

When I use scanf more than one time the program do not wait for another input. Instead it exits


I learned that I could put a blank space before the conversion specifier in the scanf-function - yes that solved the problem and I guess that has to do with the inputstream, that is - if its a newline character in the inputstream the scanf will consume it immediately.



scanf(" %f", &value);


But if its so - why could I not use the fflush(stdin) instead? I have tried but it doesnt work.



#include <stdio.h>
int main()
{

float value;
char ch;

printf("input value: ");
scanf("%f", &value);
fflush(stdin);
printf("input char: ");
scanf("%c", &ch);

return (0);
}

Aucun commentaire:

Enregistrer un commentaire