Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 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.
OzOz is offline  
Old 05-31-2005, 04:42 AM   #2 (permalink)
Upright
 
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?
Mr Cassata is offline  
Old 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*
RAGEAngel9 is offline  
Old 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..
OzOz is offline  
Old 05-31-2005, 03:37 PM   #5 (permalink)
Insane
 
Location: Vermont
Yeah this goes under my reasons why I hate Windows default behavior.
RAGEAngel9 is offline  
Old 05-31-2005, 07:16 PM   #6 (permalink)
Crazy
 
ryborg's Avatar
 
Sounds like you may need to uncheck the "Hide known file extensions" option.
__________________
Solve two problems at once. Feed the homeless to the hungry.
ryborg is offline  
Old 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.
OzOz is offline  
Old 06-01-2005, 12:35 PM   #8 (permalink)
Insane
 
trache's Avatar
 
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
trache is offline  
Old 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.
OzOz is offline  
 

Tags
fopen, problem, weird


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 09:13 PM.

Tilted Forum Project

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54