I working with trying to access a file with pFile. I save my file I want my program to open as myfile.txt format on my desktop. In Visual Studio I set my code up as:
pFile = fopen ("myfile.txt", "r");
I get back NULL and fails to open. Is there a place to store the file I'm trying to open? I can't have it on my desktop? I'm learning, so any advice would be great, thanks,
Just putting the file anywhere will not work because your program will have no way to find it. If you don't specify a directory, it will look in the "current" directory.
If you are running the exe by double-clicking it, the current directory is likely the same directory as the exe.
If you are running from the IDE, the current directory is likely the directory that your project file is in.
Alternatively, you can put a fully qualified path name in your fopen:
for example this is the path where I put the file.txt. I saved it in the same folder as the cpp file is in within visual studio. still not working. I am obvoisly missing something.
pFile = fopen("C:\\Users\Jer\Documents\Visual Studio 2010\Projects\filetemp\filetemp\file.txt","r");