/* --------------------------------------------------------------------- // Figure 15.10b: Reading a data file using the scanf() return value. // 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; int status; 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 (;;) { status = fscanf( flop, " (%lg,%lg)", &t, &v ); /* Read next input */ printf( " Status = %i", status ); 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(); }