September 5th, 2003, 07:29 AM
fopen returns null on Win 98
This is such basic code and yet I can't figure out the problem. Here's the code - explanation is beneath.
int readSettingsFile(char *filePath, char *fileContents)
// some non relevant code here ...
// open file for reading
// more non relevant code ...
The code in this function should open a file - "C:\Temp\settings.xml" - for reading (the file does exist). I pass filePath using double slashes ie "C:\\Temp\\settings.xml" and everything works fine on Windows XP/2000. However as soon as I try it on Windows 98 the fopen returns NULL. Built using MSVC++ 6.0. Have tried building on both platforms to see if that helped but it doesn't.
I'd be grateful to hear from anybody who knows why this might be happening.
September 5th, 2003, 07:40 AM
Have you even checked what errno has to say about it?
If the file does not exist and you want to create it, you should pass 'w' inside your mode string ("w+t").
September 5th, 2003, 08:29 AM
Oops - sorry.
errno returns ENOENT (2) file or directory don't exist. That's the infuriating thing - they do exist.
I've even tried writing the path directly to the fopen call ...
but I get the same problem. What could be wrong?
I don't want to destroy the contents of the existing file so haven't used "w+t". However just to see what happened I tried it but it couldn't even create the file - still returned ENOENT.
September 5th, 2003, 08:30 AM
So use "a+t", please read the documentation.
Do you even have permissions to write to the directory?
September 5th, 2003, 08:41 AM
Yes I have OK permissions. Am freely able to create files at this location. It's a problem on more than one Windows 98 pc so didn't think permissions to be an issue.