X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=progs%2Fdemos%2FLorenz%2Florenz.c;h=93ed843bae626d8e1e9e6de876f69798914a3433;hb=e603b570558abad475caac516ffea700f0b3172f;hp=f4372d62f70f83f4a084d2f730b6e106b11b6b8a;hpb=cba16355bd8a2ce3e957e680e657bfc87de2c6d7;p=freeglut diff --git a/progs/demos/Lorenz/lorenz.c b/progs/demos/Lorenz/lorenz.c index f4372d6..93ed843 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 @@ -141,16 +151,16 @@ void key_cb ( unsigned char key, int x, int y ) break ; case 'm' : case 'M' : /* Modify the Lorenz parameters */ - printf ( "Please enter new value for (default %lf, currently %lf): ", s0, sigma ) ; - fgets ( inputline, INPUT_LINE_LENGTH-1, stdin ) ; + printf ( "Please enter new value for (default %f, currently %f): ", s0, sigma ) ; + checkedFGets ( inputline, sizeof ( inputline ), stdin ) ; sscanf ( inputline, "%lf", &sigma ) ; - printf ( "Please enter new value for (default %lf, currently %lf): ", b0, b ) ; - fgets ( inputline, INPUT_LINE_LENGTH-1, stdin ) ; + printf ( "Please enter new value for (default %f, currently %f): ", b0, b ) ; + checkedFGets ( inputline, sizeof ( inputline ), stdin ) ; sscanf ( inputline, "%lf", &b ) ; - printf ( "Please enter new value for (default %lf, currently %lf): ", r0, r ) ; - fgets ( inputline, INPUT_LINE_LENGTH-1, stdin ) ; + printf ( "Please enter new value for (default %f, currently %f): ", r0, r ) ; + checkedFGets ( inputline, sizeof ( inputline ), stdin ) ; sscanf ( inputline, "%lf", &r ) ; break ; @@ -257,9 +267,9 @@ void display_cb ( void ) /* Print the distance between the two points */ glColor3d ( 1.0, 1.0, 1.0 ) ; /* White */ - sprintf ( string, "Distance: %10.6lf", distance ) ; + sprintf ( string, "Distance: %10.6f", distance ) ; glRasterPos2i ( 10, 10 ) ; - glutBitmapString ( GLUT_BITMAP_HELVETICA_12, (unsigned char *)string ) ; + glutBitmapString ( GLUT_BITMAP_HELVETICA_12, (unsigned char*)string ) ; glutSwapBuffers(); } @@ -347,7 +357,7 @@ int main ( int argc, char *argv[] ) glutMainLoop () ; #ifdef WIN32 - /* DUMP MEMORY LEAK INFORMATION */ + /* DUMP MEMORY LEAK INFORMATION */ _CrtDumpMemoryLeaks () ; #endif