If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

fopen() problem!

I have been trying to develop a program in the C language, although have struck a problem. I have written the following line of code, although it does not work in the way in which I had intended.

f=fopen ("C:\Binary","w");

I wanted this code to create a file on the C drive of my computer and open it, ready to write to. Although the code creates the file in which every directory I execute the file from, not at the file path which I have specified.

I've written up an example quickly to see if what you were doing was correct (hadn't used fopen before)...worked fine for me. Here it is, so have a look at yours and see if there's anything obviously different about the io stuff:

Re: fopen() problem!

What's your compiler anyway? I tried your code on gcc and f returned NULL (it didn't even create the file in current directory).

Peace always,&lt;jdenny&gt;

Always listen to experts. They\'ll tell you what can\'t be done and why. Then go and do it. -- Robert HeinleinI\'m basically a very lazy person who likes to get credit for things other people actually do. -- Linus Torvalds

well, in C the '\' is used to print certain characters (like " \ ) to deactivate their normal values/
hope this makes sense

just like you need a '\n' for a newline, instead of just an 'n', so also works the '\'. normally the '\' is used in combination with the character right after it, and therefore you need to deactivate it using '\\' to have just the one backslash with no value.

i really hope this makes sense, since at this moment, i wouldn't know how to make it more clear

**EDIT**well, he posted it at the same time , but i think his explanation is more clearer **/EDIT**

jdenny said that when using gcc, to compile the program, the compiled program didn't execute as it did when I compiled the program using visual c++. Although I thought that the code would be compiled into the same executable, whether one uses visual c++ or gcc to compile the code.

jdenny said that when using gcc, to compile the program, the compiled program didn't execute as it did when I compiled the program using visual c++. Although I thought that the code would be compiled into the same executable, whether one uses visual c++ or gcc to compile the code.

Could anyone tell me if I am correct or not?

(assuming gcc for linux) no it would not, otherwise you could run every program written in linux on a windows computer and visa versa (without the use of wine or cigwin).
i can't tell you exactly whats the difference, but even between different kernel versions you might need to recompile the program.

as for different compilers and same OS, they all have their own rules and ways to compile, one compiler might be compiling for performance, while the other might compile for lesser size. this is just one of the differences..