home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / c / 16221 < prev    next >
Encoding:
Text File  |  1992-11-09  |  1.6 KB  |  41 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: Finding length of file?
  5. Message-ID: <1992Nov9.191316.11833@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <BxF36F.CwA@ux1.cso.uiuc.edu>
  8. Date: Mon, 9 Nov 1992 19:13:16 GMT
  9. Lines: 30
  10.  
  11. ceblair@ux1.cso.uiuc.edu (Charles Blair) writes:
  12.  
  13.  
  14. >  Sorry if this is an FAQ, I couldn't find it in any of the current 
  15. >postings.
  16.  
  17. >  I have created a file for reading using fopen.  Is there a simple
  18. >quick way to find out how many bytes there are until EOF?  I would
  19. >prefer something that is part of the standard, which I think rules
  20. >out the read command.  I thought I might be able to do this using
  21. >p -> cnt for p a pointer to FILE, but that didn't work.
  22.  
  23. The only Standard-conforming and portable way to find out how many
  24. bytes are in a file is to open the file (or seek to its beginning),
  25. and read bytes until EOF, keeping track of how many you read.
  26.  
  27. Because of the diversity of file systems, you are not guaranteed in
  28. either text or binary mode that what you wrote to a file is precisely
  29. what is in the file.  That is, for example, lines in a text file might
  30. have more or fewer trailing blanks than you wrote, and a binary file
  31. might have more or fewer trailing nulls than you wrote.  There are
  32. other issues as well.
  33.  
  34. C implementations often provide functions which tell you many things
  35. about files, including size.  For example, stat() and fstat() are
  36. common functions, but not part of the C Standard.
  37. -- 
  38.  
  39. Steve Clamage, TauMetric Corp, steve@taumet.com
  40. Vice Chair, ANSI C++ Committee, X3J16
  41.