2
votes

I'm using "Visual Studio 2010" on "Windows 7 32bit", and I'm working on my "debug" build.

In my program I use fopen to access a file using this code:

FILE *f = fopen("simple_test.asm", "r");

When I run (F5) it returns a NULL pointer. When I use full path it works well.

The strange thing is, when I open the file through cmd, it works like a charm even when I don't use full path!

Can someone please shed some light on this? Thanks!

2
Sounds like an issue with the working directory. In the cmd shell, you might be in a different directory than visual studio uses to run your program. You should be able to set the working directory in the Project Settings: msdn.microsoft.com/en-us/library/kcw4dzyf.aspx - millimoose
The debugger might start it up with a different current directory. Does it work if you pass a fully-qualified path to fopen? - Joe White
@ruakh I dislike guessing (too much) in answers, I'll just repost if the guess turns out to be right. - millimoose
It was a problem with current directory - VS2010 sets it differently then I expected. Thanks everybody. - Danish

2 Answers

2
votes

The current directory for Visual Studio 2010 might not be the directory that has simple_test.asm.

As simple as that.

1
votes

fopen takes a second argument specifing the mode, "r" for read "r+" for reading and writing and so on.

FILE *fopen(const char *path, const char *mode);