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 12:59 AM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360