# opening a file to read

This is a discussion on opening a file to read within the C Programming forums, part of the General Programming Boards category; this is just a quick question should be easy... but if im opening a file to be read in like ...

1. ## opening a file to read

this is just a quick question should be easy... but if im opening a file to be read in like input.txt where do i put the input.txt file?

2. You put it in the same directory as your executable. Should be fine in most of the cases, except if you are drog and drapping file on your executable (in Windows) where you'll now need the complete path (ex. "C:/a_folder/my_file.txt") to reach the correct file....

3. worked great thanks i thought thats where it needed to go but for some odd reason it wasnt working fiddled with it now it does thanks!

4. Actually, you don't have to put it in the same directory. You're supposed to give it the full path. But if fopen does only finds a file name with no path, then it searches it's current directory.

e.g. If the file called text.txt and is placed in C:\ you can either open it with
Code:
fopen("C:\\text.txt", "r");
Note that '\\' is needed since \ is used as an escape sequence.

OR you can place the file in C:\ and run it with
Code:
fopen("text.txt", "r");
Hope I helped