Reputation: 457
I have wrote a set of code that scan in values and use them to test out central limit theorem. However when I run my program after I input all the values using scanf my program is not proceeding to the next lines of code : the problem looks like this:
printf("*** DEMONSTRATION OF CENTRAL LIMIT THEOREM ***");
printf("Enter parameters for the distribution [a b] ==> ");
scanf("%f %f",&a,&b);
printf("Enter distribution to display [1=data, 2=mean] ==> ");
scanf("%d",&option);
printf("Enter number in each group ==> ");
scanf("%d",&group);
printf("Enter number of samples of groups ==> ");
scanf("%f",×);
printf("are we here yet");
after these printf and scanf the program starts to do the calculations. But When I run the program after I compile(successfully). It seems my code is stuck after the scanf("%f",×);
the line "are we here yet" never gets printed, meaning the program did not get past the scanf. I have not done much C programming this seemed really strange to me can someone figure out why the program is not excuting past the line scanf("%f",×); I really appericate it
Upvotes: 2
Views: 7408
Reputation: 25908
Input/output at the terminal is line-buffered in C, and output is not going to display until you output a newline character, or you call fflush(stdout)
, or your program terminates normally and all the buffers are flushed anyway. Change:
printf("are we here yet");
to:
printf("are we here yet\n");
or:
printf("are we here yet");
fflush(stdout);
and you should see your output.
Upvotes: 2