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

  1. Newsgroups: comp.lang.c
  2. From: sff@mobrad.demon.co.uk.demon.co.uk (Sean Fitt)
  3. Path: sparky!uunet!digex.com!intercon!udel!bogus.sura.net!howland.reston.ans.net!spool.mu.edu!agate!doc.ic.ac.uk!pipex!demon!mobrad.demon.co.uk.demon.co.uk!sff
  4. Subject: Re: Turbo C FOPEN error
  5. Reply-To: sff@mobrad.demon.co.uk.demon.co.uk
  6. References: <1993Jan27.053643.21953@news.cs.brandeis.edu>
  7. Distribution: world
  8. X-Mailer: cppnews $Revision: 1.30 $
  9. Organization: Mobile Radio Limited
  10. Lines: 52
  11. Date: Wed, 27 Jan 1993 17:21:28 +0000
  12. Message-ID: <728180488snx@mobrad.demon.co.uk.demon.co.uk>
  13. Sender: usenet@demon.co.uk
  14.  
  15. In article <1993Jan27.053643.21953@news.cs.brandeis.edu> gilmour@binah.cc.brandeis.edu writes:
  16. > I can't figure out what's wrong.  This program works fine as long as there's
  17. > less than 16 files (it doesn't actually matter what drive).  I haven't come
  18. > across anything explaining it in the manual.  The error happens at runtime 
  19. > during the 'stream = fopen(name...' line.  Anybody?
  20.  
  21. [Part of Program deleted]
  22.  
  23. >         done = _dos_findfirst("a:*.*", _A_NORMAL, &test);
  24. >         while (!done) {
  25. >                 strcpy(name, "a:");
  26. >                 strcat(name, test.name);
  27. >                 if ((stream = fopen(name, "r")) == NULL) {
  28. >                         printf("Error in opening filename.\n");
  29. >                         exit (1);
  30. >                 }
  31. >  
  32. >                 getftime(fileno(stream), &ft);
  33. >                 printf("%-16s%7lu\t%2u/%02u/%u\n", name,
  34. >                         test.size, ft.ft_month,
  35. >                         ft.ft_day, ft.ft_year+1980);
  36. >                 done = _dos_findnext(&test);
  37. >         }
  38. >         fclose(stream);
  39.  
  40. [Rest Deleted]
  41.  
  42. Your problem is you're not closing the file after obtaining the information
  43. you require - you're closing *one* file at the end of the program. What this
  44. means in real terms is that you're exceeding the maximum number of files
  45. which can be opened at any one time.
  46.  
  47. Try moving the 'fclose(stream)' line to just before the 
  48. 'done = _dos_findnext(&test)' line, and it should work.
  49. i.e.
  50.                 printf("%-16s%7lu\t%2u.%02u/%u\n", name
  51.                         test.size, ft.ft_month,
  52.                         ft.ft_day, ft.ft_year+1980);
  53.                 fclose(stream);
  54.                 done = _dos_findnext(&test);
  55.  
  56. Sean.
  57.  
  58. ==============================================================================
  59. | Sean Fitt                          | My views are those with which I was   |
  60. | sff@mobrad.demon.co.uk             | indoctrinated from a very early age.  |
  61. | naffcode@cix.compulink.co.uk       | Please don't blame me if you don't    |
  62. | 100034.2166@compuserve.com         | agree with them.                      |
  63. |----------------------------------------------------------------------------|
  64. | demon is a subscription site, and mobrad are not connected or related in   |
  65. |                any way to any other demon subscribers                      |
  66. ==============================================================================
  67.