Thread: Why is tmpfile returning my stderr message?

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    34

    Why is tmpfile returning my stderr message?

    Code:
    FILE *OpenTemporaryFile(void)
    {
      FILE *pFile;
      if((pFile = tmpfile()) == NULL)
      {
         fprintf(stderr, "Cant open temp file\n");
         exit(EXIT_FAILURE);
      }
      return pFile;
    }
    I'm a novice coder, but I'm pretty sure I've coded this correctly? Help?

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Seems to work fine for me. Can you try to re-compile and run it again?

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    tmpfile() is presumably failing on your system. The reasons vary between systems (eg with operating system, compiler/library, and resources available on your system).

    A common reason for failure is that files cannot be created in the current working directory. Reasons that might occur vary, but include a working directory that does not exist, a working directory on a hard drive with no spare space, and things like that.

    Another common reason is that your program already has several file handles already open, sufficient that some quota (eg set by an administrator, or a default operating system limit) is exceeded.

    Without information on the code that is calling your function, or the system on which your program is running, it is not possible to give a more specific response.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Message loop?
    By Shadowwoelf in forum Windows Programming
    Replies: 2
    Last Post: 07-21-2007, 09:58 PM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. fprintf to stderr crash programs
    By jlai in forum Windows Programming
    Replies: 2
    Last Post: 04-12-2005, 08:51 AM
  4. input/output
    By dogbert234 in forum Windows Programming
    Replies: 11
    Last Post: 01-26-2005, 06:57 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM