home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!rpi!batcomputer!munnari.oz.au!goanna!ok
- From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
- Newsgroups: comp.lang.c
- Subject: Re: problem with foef()
- Message-ID: <15987@goanna.cs.rmit.oz.au>
- Date: 17 Nov 92 08:40:30 GMT
- References: <92316.213238U17868@uicvm.uic.edu>
- Organization: Comp Sci, RMIT, Melbourne, Australia
- Lines: 40
-
- In article <92316.213238U17868@uicvm.uic.edu>, U17868@uicvm.uic.edu writes:
- > I am reading a binary file with fread.
-
- Then you don't need feof(). The basic paradigm for C input is
-
- while (try_to_read(...) SUCCEEDS) {
- use_the_input(...);
- }
- the loop stopped because of EOF or because of error,
- use feof() to tell which.
-
- > #include "header.h"
-
- > void dispdail(date)
- > char date[9];
-
- WHOOPS! This does not mean what you think it does! A simple rule of
- thumb which will help you get C functions right is
- *NEVER* use [] in the arguments of a function.
- Look under "argument promotion rules" in the index of any good C text.
-
- Use
- void dispdail(date)
- char *date; /* or char date[]; if you _must_ */
- > {
- > int i, j, a;
- > FILE *activity_file; /* was 'file_pointer' which is */
- /* a very unhelpful name */
- > struct activity temp;
-
- > activity_file = fopen("activity.dat", "rb");
- assert(activity_file != NULL);
- /* There is no need to use fseek(), "rb" starts at the beginning */
- while (frad(&temp, sizeof temp, 1, activity_file) == 1) {
- ... use this activity record ...
- }
- assert(feof(activity_file));
- fclose(activity_file);
- > } /* end dispdail */
-
-