111 likes | 214 Views
feof. ATS 315. feof. When we read in the files with the hourly observations, we need to read one observations from each station. Sounds like a loop! However, a different number of stations will report each hour. Sounds like a “while” loop to me!. feof. Starting a while loop…. main () {
E N D
feof ATS 315
feof • When we read in the files with the hourly observations, we need to read one observations from each station. • Sounds like a loop! • However, a different number of stations will report each hour. • Sounds like a “while” loop to me!
feof • Starting a while loop… main () { FILE *fin; fin = fopen(“decoded.data2”,”r”); while ( ) { /* Read in one observation */ } fclose (fin); }
feof • …but what goes here? main () { FILE *fin; fin = fopen(“decoded.data2”,”r”); while ( ) { /* Read in one observation */ } fclose (fin); }
feof • while ( we are not done reading the file) { main () { FILE *fin; fin = fopen(“decoded.data2”,”r”); while ( ) { /* Read in one observation */ } fclose (fin); }
feof • while ( we are not at the end of the file ) { main () { FILE *fin; fin = fopen(“decoded.data2”,”r”); while ( ) { /* Read in one observation */ } fclose (fin); }
feof • while ( we are not at the eof ) { main () { FILE *fin; fin = fopen(“decoded.data2”,”r”); while ( ) { /* Read in one observation */ } fclose (fin); }
feof • while ( we are not at the eof of fin ) { main () { FILE *fin; fin = fopen(“decoded.data2”,”r”); while ( ) { /* Read in one observation */ } fclose (fin); }
feof • while ( we are not at feof(fin) ) { main () { FILE *fin; fin = fopen(“decoded.data2”,”r”); while ( ) { /* Read in one observation */ } fclose (fin); }
feof • while ( !feof(fin) ) { main () { FILE *fin; fin = fopen(“decoded.data2”,”r”); while (!feof(fin) ) { /* Read in one observation */ } fclose (fin); }
#include<math.h> #include<stdio.h> main () { FILE *fin; float tempC,dewpC,wspd,wdir,pressMB; int count; fin = fopen ("decoded.data2","r"); count = 0; while (!feof(fin)){ fscanf (fin,"%f %f %f %f %f", &tempC,&dewpC,&wspd,&wdir,&pressMB); count++; printf ("%d %f\n",count,pressMB); } fclose (fin); } 1 1009.400024 2 996.200012 3 1000.599976 4 1005.700012 5 998.599976 6 992.700012 7 996.900024 8 997.900024 9 994.900024 10 996.000000 11 996.799988 12 1008.000000 … 338 1003.099976 339 1007.200012 340 999.700012 341 1000.599976 342 991.200012 343 991.200012