/* --------------------------------------------------------------------- // Figure 15.10: Reading a data file. // Read and echo a data file with two numbers on each line, in point // coordinate format, (x, y). // Correct end-of-file processing depends on presence of a newline // character after every data item in file, including the last. // --------------------------------------------------------------------- */ #include "tools.h" void main( void ) { double t, v; char file_name[80]; /* Full path name of file we will read. */ stream flop; banner(); /* Create stream and open file. ------------------------------------*/ printf( " What file do you want to read? "); scanf( " %79[^\n]", file_name ); /* Read entire line. */ flop = fopen( file_name, "r" ); if (flop == NULL) fatal( " Cannot open %s for reading.\n", file_name ); for (;;) { fscanf( flop, " (%lg,%lg)", &t, &v ); /* Read next input. ------ */ if (feof( flop )) break; /* Test stream status. --- */ printf( "%8.2f %14.2f \n", t, v ); /* Echo input. ----------- */ /* Process the input here, if processing is needed. ------------ */ } fclose( flop ); bye(); }