home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20320 < prev    next >
Encoding:
Text File  |  1993-01-28  |  2.8 KB  |  78 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!spool.mu.edu!howland.reston.ans.net!usc!elroy.jpl.nasa.gov!decwrl!pacbell.com!UB.com!pippen.ub.com!rfries
  3. From: rfries@sceng.ub.com (Robert Fries)
  4. Subject: Re: Turbo C FOPEN error
  5. Message-ID: <rfries.184@sceng.ub.com>
  6. Sender: news@pippen.ub.com (The Daily News)
  7. Nntp-Posting-Host: 128.203.1.151
  8. Organization: Ungermann Bass
  9. References: <1993Jan27.053643.21953@news.cs.brandeis.edu>
  10. Date: Thu, 28 Jan 1993 16:14:11 GMT
  11. Lines: 65
  12.  
  13. In article <1993Jan27.053643.21953@news.cs.brandeis.edu> gilmour@binah.cc.brandeis.edu (Jeffrey R. Gilmour) writes:
  14.  
  15. >I can't figure out what's wrong.  This program works fine as long as there's
  16. >less than 16 files (it doesn't actually matter what drive).  I haven't come
  17. >across anything explaining it in the manual.  The error happens at runtime 
  18. >during the 'stream = fopen(name...' line.  Anybody?
  19.  
  20. >/*
  21. >**      FOPENERR.C
  22. >*/
  23. >#include "stdio.h"
  24. >#include "io.h"
  25. >#include "dos.h"
  26. >void main(void)
  27. >{
  28. >        int done;
  29. >        char name[15];
  30. >        struct find_t test;
  31. >        struct ftime ft;
  32. >        FILE *stream;
  33. >        done = _dos_findfirst("a:*.*", _A_NORMAL, &test);
  34. >        while (!done) {
  35. >                strcpy(name, "a:");
  36. >                strcat(name, test.name);
  37. >                if ((stream = fopen(name, "r")) == NULL) {
  38. >                        printf("Error in opening filename.\n");
  39. >                        exit (1);
  40. >                }
  41. >                getftime(fileno(stream), &ft);
  42. >                printf("%-16s%7lu\t%2u/%02u/%u\n", name,
  43. >                        test.size, ft.ft_month,
  44. >                        ft.ft_day, ft.ft_year+1980);
  45. >                done = _dos_findnext(&test);
  46. >        }
  47. >        fclose(stream);
  48. >}
  49.  
  50. >___________________________________ 
  51. >|__/~~~~~\__/~~~~\__/~~~~\__/~~~~\_|/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  52. >|____/~\____/~\_____/~\_____/~\____|\                                          /
  53. >|____/~\____/~~~\___/~~~\___/~~~\__|/   T h i s   S p a c e   f o r   R e n t  \
  54. >|____/~\____/~\_____/~\_____/~\____|\                                          /
  55. >|__/~~~\____/~~~~\__/~\_____/~\____|/       GILMOUR@BINAH.CC.BRANDEIS.EDU      \
  56. >|__________________________________|\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  57.  
  58. Probably caused by having too many open files. Put the fclose(stream) call 
  59. inside your loop; right after the call to getftime() looks like a good place.
  60.  
  61. As it is, your program only explicitly closes the last file it opened,
  62. and all files are closed automatically when your program terminates.
  63.  
  64. Robert
  65.  
  66. //////////////////////////////////////////////////////////////////////////
  67. Robert Fries
  68. Ungermann-Bass Inc.
  69.  
  70. DISCLAIMER:
  71.     Opinions contained herein are my own, and are not necessarily those
  72.     of Ungermann-Bass.
  73. //////////////////////////////////////////////////////////////////////////
  74.