X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=progs%2Fdemos%2FLorenz%2Florenz.c;h=5c05c8ddcdc489e0cf319f2ded36de4f86f1692d;hb=6a3b098cf4201b8360824a398388f50d474184b4;hp=f2de979259e72fc6b524c14dbefbf58e6a5a35da;hpb=22331701e4f069a5e222465ea7c95aa3a584821f;p=freeglut diff --git a/progs/demos/Lorenz/lorenz.c b/progs/demos/Lorenz/lorenz.c index f2de979..5c05c8d 100644 --- a/progs/demos/Lorenz/lorenz.c +++ b/progs/demos/Lorenz/lorenz.c @@ -107,6 +107,16 @@ void advance_in_time ( double time_step, double position[3], double new_position ( deriv0[i] + 2.0 * ( deriv1[i] + deriv2[i] ) + deriv3[i] ) ; } +static void +checkedFGets ( char *s, int size, FILE *stream ) +{ + if ( fgets ( s, size, stream ) == NULL ) { + fprintf ( stderr, "fgets failed\n"); + exit ( EXIT_FAILURE ); + } +} + + /* GLUT callbacks */ #define INPUT_LINE_LENGTH 80 @@ -142,15 +152,15 @@ void key_cb ( unsigned char key, int x, int y ) case 'm' : case 'M' : /* Modify the Lorenz parameters */ printf ( "Please enter new value for (default %f, currently %f): ", s0, sigma ) ; - fgets ( inputline, INPUT_LINE_LENGTH-1, stdin ) ; + checkedFGets ( inputline, sizeof ( inputline ), stdin ) ; sscanf ( inputline, "%lf", &sigma ) ; printf ( "Please enter new value for (default %f, currently %f): ", b0, b ) ; - fgets ( inputline, INPUT_LINE_LENGTH-1, stdin ) ; + checkedFGets ( inputline, sizeof ( inputline ), stdin ) ; sscanf ( inputline, "%lf", &b ) ; printf ( "Please enter new value for (default %f, currently %f): ", r0, r ) ; - fgets ( inputline, INPUT_LINE_LENGTH-1, stdin ) ; + checkedFGets ( inputline, sizeof ( inputline ), stdin ) ; sscanf ( inputline, "%lf", &r ) ; break ; @@ -258,7 +268,7 @@ void display_cb ( void ) /* Print the distance between the two points */ glColor3d ( 1.0, 1.0, 1.0 ) ; /* White */ sprintf ( string, "Distance: %10.6f", distance ) ; - glRasterPos2i ( 10, 10 ) ; + glRasterPos2i ( 1, 1 ) ; glutBitmapString ( GLUT_BITMAP_HELVETICA_12, (unsigned char*)string ) ; glutSwapBuffers();