I'm a novice coder, but I'm pretty sure I've coded this correctly? Help?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?Code:FILE *OpenTemporaryFile(void) { FILE *pFile; if((pFile = tmpfile()) == NULL) { fprintf(stderr, "Cant open temp file\n"); exit(EXIT_FAILURE); } return pFile; }
Seems to work fine for me. Can you try to re-compile and run it again?
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.