1 / 11

feof

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 () {

susan-rush
Download Presentation

feof

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. feof ATS 315

  2. 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!

  3. feof • Starting a while loop… main () { FILE *fin; fin = fopen(“decoded.data2”,”r”); while ( ) { /* Read in one observation */ } fclose (fin); }

  4. feof • …but what goes here? main () { FILE *fin; fin = fopen(“decoded.data2”,”r”); while ( ) { /* Read in one observation */ } fclose (fin); }

  5. feof • while ( we are not done reading the file) { main () { FILE *fin; fin = fopen(“decoded.data2”,”r”); while ( ) { /* Read in one observation */ } fclose (fin); }

  6. 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); }

  7. feof • while ( we are not at the eof ) { main () { FILE *fin; fin = fopen(“decoded.data2”,”r”); while ( ) { /* Read in one observation */ } fclose (fin); }

  8. 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); }

  9. feof • while ( we are not at feof(fin) ) { main () { FILE *fin; fin = fopen(“decoded.data2”,”r”); while ( ) { /* Read in one observation */ } fclose (fin); }

  10. feof • while ( !feof(fin) ) { main () { FILE *fin; fin = fopen(“decoded.data2”,”r”); while (!feof(fin) ) { /* Read in one observation */ } fclose (fin); }

  11. #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

More Related