Too many files open?

This is a discussion on Too many files open? within the C++ Programming forums, part of the General Programming Boards category; I keep getting an error saying that I have too many files open when trying to open a file. I ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    119

    Too many files open?

    I keep getting an error saying that I have too many files open when trying to open a file. I have a function that gets called a lot of times and I'm trying to trace some stuff going on in that function. So when I enter the function, I open a file to append to, write some stuff to it, and then close it. After a while, when I try to open the file to append to, I get a seg fault because too many files are open. My code is basically:

    Code:
    FILE *fp = fopen(outFile, "a+");
    if(fp!=NULL){
     fprintf(fp,"stuff\n");
     fclose(fp);
    }else{
     printf("Error opening file\n");
    }
    is there some other way I'm supposed to close the file?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,662
    Welcome.

    There's nothing wrong with what you posted. If you provide us with a complete source sample that reproduces your issue, and the compiler/environment in which you're running - we should be able to help.

    gg

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,498
    What your error message is telling you is there are a lot more fopen calls than fclose calls.

    So whilst your approximation of the problem is impeccable, the reality of your situation is different.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Open Source Licenses
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 10-10-2006, 08:53 PM
  2. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 01:41 PM
  3. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  4. Open GL header files
    By Rune Hunter in forum C++ Programming
    Replies: 1
    Last Post: 10-03-2005, 01:10 AM
  5. reinserting htm files into chm help files
    By verb in forum Windows Programming
    Replies: 0
    Last Post: 02-15-2002, 08:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21