Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
getc/fgets
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Richard Weeks, post: 2994013"] Below is a fragment from a program that calculates statistics on x,y data. I want the user to be able to predict one or more predicted values of y from x, given the line of best fit. I have a procedural problem. predict: printf("\npredict y? (y/n): "); if((getc(stdin)=='n')) exit(EXIT_SUCCESS); //if((fgets(response, 1, stdin)=="n")) exit(EXIT_SUCCESS); else { printf("\nenter x: "); scanf("%lf", &xdatum); printf("\ny = %f\n", y_int + (slope * xdatum)); fflush(stdin); goto predict; } It works fine using getc, but when I use fgets execution jumps directly into the else{} block and prompts for x without waiting for user response to the y/n prompt. What am I doing wrong? Richard [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
getc/fgets
Top