05-31-2005, 04:40 AM | #1 (permalink) |
Psycho
Location: Right here, right now.
|
Weird fopen problem in C++ - help?
I've been writing a program and have found a weird problem on my PC. I traced it to a call to fopen, which for some strange reason has suddenly become extremely selective about which files it chooses to see. I tried writing a tiny test app to check that I was using fopen correctly, and I still see the same problem there. The test app is very simple:
#include <stdlib.h> #include <stdio.h> int main(void) { FILE *pFile; int i = 0; char c; pFile = fopen("C:\\XMLTest.txt", "r"); if(pFile) { c = fgetc(pFile); fclose(pFile); } else { i = errno; } return 0; } I'm still finding that it will pick up some files, but not all. The one shown here - nothing. It's giving errno = 2, which means that the file or directory doesn't exist. I assure you, it most definitely does exist. What else could be causing this, and in such a selective manner? Anyone have any ideas? I'm clean out of them. Thanks in advance for your help.
__________________
Maybe you should put some shorts on or something, if you wanna keep fighting evil today. |
05-31-2005, 09:01 AM | #3 (permalink) |
Insane
Location: Vermont
|
No he's fine on the dec's and init's.
One issue could be does the file have read and write permission? I frankly don't know as much about windows as *nix, but I assume file rules still apply. I tried to find a list of errno symbols and numbers, but no all the fucking internet has is the name and description. *sigh* |
05-31-2005, 12:22 PM | #4 (permalink) |
Psycho
Location: Right here, right now.
|
Thanks for your responses guys. I figured out what was wrong.
The code was working fine. On going into the command window to check the file attributes, I discovered that the name of the file I was trying to open wasn't "XMLTest.txt" but "XMLTest.txt.txt" - I had changed the name in Windows Explorer and for some reason it had kept the extra .txt on the end. I removed that and all was well. So, it had read and write permission (as per RAGE's suggestion, which was what I was checking) - it just didn't have the name I wanted it to have. As a wise man once said, "AAAARRRRGGGGHHHH!!!!"
__________________
Maybe you should put some shorts on or something, if you wanna keep fighting evil today. Last edited by OzOz; 05-31-2005 at 12:24 PM.. |
06-01-2005, 01:54 AM | #7 (permalink) |
Psycho
Location: Right here, right now.
|
Indeed I do and have done now. It sounds like a very dangerous bit of default behaviour to me.
Code works just fine now, now that I can see what everything really is!
__________________
Maybe you should put some shorts on or something, if you wanna keep fighting evil today. |
06-01-2005, 12:35 PM | #8 (permalink) |
Insane
|
OzOz:
I feel your pain. Cue dangerous Outlook viruses <here>. Can we spell NIMDA? Yay boys and girls. *kicks the ever damning soul of the virus author and Microsoft for keeping this as the default behaviour as well as not having correct GODDAMN file extension parsing routines which allowed .txt.exe and similar to go unnoticed even until Windows 2000!*
__________________
"You looked at me as if I was eating runny eggs in slow motion." - Gord Downie of The Tragically Hip |
06-02-2005, 12:18 AM | #9 (permalink) |
Psycho
Location: Right here, right now.
|
trache, ouch! That's what this incident had me afraid of. (At first, I was wondering if somehow I had gotten infected.) Luckily I've escaped that sort of thing. It's the main reason why I avoid Outlook like the plague at home.
__________________
Maybe you should put some shorts on or something, if you wanna keep fighting evil today. |
Tags |
fopen, problem, weird |
|
|