X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=progs%2Fdemos%2FLorenz%2Florenz.c;h=5c05c8ddcdc489e0cf319f2ded36de4f86f1692d;hb=6a3b098cf4201b8360824a398388f50d474184b4;hp=be32c771c226a3c8ad608624afe5bb7ce93493d0;hpb=89c225066899f8956939f8175a0d548cd6f63a62;p=freeglut diff --git a/progs/demos/Lorenz/lorenz.c b/progs/demos/Lorenz/lorenz.c index be32c77..5c05c8d 100644 --- a/progs/demos/Lorenz/lorenz.c +++ b/progs/demos/Lorenz/lorenz.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #ifdef WIN32 /* DUMP MEMORY LEAKS */ @@ -108,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 @@ -143,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 ; @@ -259,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();