home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / SNIP9404.ZIP / ANSIFLEN.C < prev    next >
C/C++ Source or Header  |  1994-04-03  |  628b  |  35 lines

  1. /*
  2. **  FLENGTH.C - a simple function using all ANSI-standard functions
  3. **              to determine the size of a file.
  4. **
  5. **  Public domain by Bob Jarvis.
  6. */
  7.  
  8. #include <stdio.h>
  9.  
  10. long flength(char *fname)
  11. {
  12.       FILE *fptr;
  13.       long length = -1L;
  14.  
  15.       fptr = fopen(fname, "rb");
  16.       if(fptr != NULL)
  17.       {
  18.             fseek(fptr, 0L, SEEK_END);
  19.             length = ftell(fptr);
  20.             fclose(fptr);
  21.       }
  22.  
  23.       return length;
  24. }
  25.  
  26. #ifdef TEST
  27.  
  28. main(int argc, char *argv[])
  29. {
  30.       printf("Length of %s = %ld\n", argv[0], flength(argv[0]));
  31.       return 0;
  32. }
  33.  
  34. #endif /* TEST */
  35.