home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / vc / pro3 / flen.c < prev    next >
Encoding:
Text File  |  1993-06-10  |  1.5 KB  |  41 lines

  1. ===========================================================================
  2.  BBS: The Abacus * HST/DS * Potterville, MI
  3. Date: 06-06-93 (12:16)             Number: 84
  4. From: JOHN GREEP                   Refer#: NONE
  5.   To: JEFFERY FOY                   Recvd: NO  
  6. Subj: Finding a file's length        Conf: (36) C Language
  7. ---------------------------------------------------------------------------
  8. JF>Short of reading a file byte by byte, what's the best way to
  9. JF>determine a file's length in bytes? (*exact* length that is)
  10.  
  11. ___-Cut-Here-------------------8<----------------------------
  12.  
  13. long file_length (FILE *fp)
  14. {
  15.         long old_pos, length;
  16.  
  17.         old_pos = ftell(fp);    /* Save file position */
  18.  
  19.         fseek (fp, 0L, SEEK_END);
  20.         length = ftell(fp);     /* Seek to end and get new position */
  21.  
  22.         fseek (fp, old_pos, SEEK_SET); /* Restore old file position */
  23.  
  24.         return length;
  25. }
  26.  
  27. ___-Cut-Here-------------------8<----------------------------
  28.  
  29. It is important to remember that file_length returns a long int and
  30. a pointer to an open file.
  31.         _____________
  32.         _/ () |-| /\/
  33.  
  34.  * OLX 2.1 TD * If this were an actual tagline, it would be funny.
  35.  
  36. --- Maximus 2.01wb
  37.  * Origin: SECRET C::The C Source*HST DS*(403)256-7019,Calgary,Ab (1:134/21)
  38. SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
  39. SEEN-BY: 153/752 154/40 77 157/110 159/100 125 430 575 950 203/23 209/209
  40. SEEN-BY: 261/1023 280/1 390/1 396/1 5 15 2270/1 2440/5 3603/20
  41.