![]() |
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. |
I don't know that much about C++, but aren't you meant to declare + initialize a variable before making a pointer to said variable?
|
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* |
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. :confused: As a wise man once said, "AAAARRRRGGGGHHHH!!!!" |
Yeah this goes under my reasons why I hate Windows default behavior.
|
Sounds like you may need to uncheck the "Hide known file extensions" option.
|
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! :) |
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!* |
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.
|
All times are GMT -8. The time now is 05:14 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project