tags:

views:

166

answers:

4

Maybe I just have another black out but, this one line is giving me a lot of troubles:

FILE *fp = fopen("data/world.data", "rb");

This works fine under Linux when compiled with GCC. But when I compile it with Visual Studio, it crashes. fp is always NULL. Both the BIN and the EXE are in the exact same directory. Now, to make things even crazier, when I run the EXE using Wine under Linux... it... works...

I have absolutely not a god damn clue what's going on here. Maybe it's some insanely stupid mistake on my side, but I cannot get this thing to run under Windows :/

Also, I have another program which works just fine, there the data files are also contained in a sub directory named data.

EDIT:
To make it clear neither / NOR `\ * do work.

EDIT 2:
OK I've given up on this, maybe someone has fun trying to figure it out, here's ZIP containing the EXE, Debug Data for VS etc.:
https://dl.dropbox.com/u/2332843/Leaf.zip

EDIT 3:
Compiled it with CodeBlocks and MinGW, works like a charm. Guess it has to do something with MSVC or the Project Settings in VS.

A: 

I'm not sure but it may be because you're using slash instead of (an escaped) backslash in the path?

nico
The other program also usese `/`, and I've already tried it with `\\ `, no difference just another crash :/
Ivo Wetzel
You can use slashes instead of backslashes on win2000, and winxp with no problem. They may cause problems on win98 and below. Not sure if it is documented feature or if it is officially supported on vista or above.
SigTerm
@SigTerm: *all* versions of Windows have accepted forward slashes just fine -- and MS-DOS back to the first versions that supported subdirectories at all (2.x) did as well. A (very) few early versions of MS-DOS even allowed you to set it to accept '/' and '-' in place of '\' and '/' respectively (i.e., follow UNIX conventions) at the command line.
Jerry Coffin
@Jerry Coffin: I said "may", which means I'm not sure. And I said only because people once reported that program (that has been using forward slashes) refused to work properly on win98. Since I could not debug program on that machine, I do not know if path separators were causing the problem. Also, if you're sure that it is supported behavior, it would be nice if you gave some link from msdn where this behavior is officially documented. This would easily end all arguments.
SigTerm
@SigTerm: I wasn't trying to say you were wrong at all -- just that you were even more right that you may have realized. @akira has already provided an MSDN link in a comment on the original question. I doubt at this late date we're going to find a lot on MSDN about something as old as Windows 98, 95, 2.11, MS-DOS 3.3, etc.
Jerry Coffin
A: 

Does the path separator matter? \ vs /.

eduffy
Windows will accept either '/' or '\'. The command line parser in cmd.exe (for one example) assumes that only '\' is a path separator, but `fopen`, `CreateFile`, etc., work fine with '/'.
Jerry Coffin
+4  A: 

It sounds like data isn't a subdirectory of your current directory when you run the program. By default (for x86 targets) VS will build and run your program from either a DEBUG or RELEASE subdirectory of the base directory you've created for the project. You can modify the directory that will be "current" when it runs though (e.g., project | properties | configuration properties | debugging for VS 2008).

Edit: While Windows requires that you use a backslash as a directory separator at the command line, a forward slash works fine in code -- this is not the source of your problem.

Jerry Coffin
I moved the program out to a few different places together with the data folder, on my Desk into the Dropbox where I can run it both on Win and Linux, it always crashes on Win, but it runs just fine under Wine.
Ivo Wetzel
@Ivo: have you tried using an absolute path to your data directory, to ensure it's found regardless of the executable's location?
Jerry Coffin
I've tried nearly everything by now, I moved around the code that calls the function which contains the fopen call, stripped out other calls to fopen etc. It's just the call to `fopen("data/world.data", "rb");` that fails, I've got others that succeed. Guess I just gonna try compiling it with Code::Blocks, Visual Studio is so F***ING SLOW on my netbook anyways. And yep, I've tried it on a different Windows Machine already.
Ivo Wetzel
A: 

Include a line to GetCurrentDirectory(), to see if you are running from the directory you expected.

When I develop in C#/ C++ on visual studio, I normally get to run it from the debug folder. I don't think it matters if forward slash is used in place of backslash in .net.

Blessed Geek