June 10th, 2013, 04:14 PM
How do I locate the files using the fopen function?
This is the example given in the textbook:
So I created the file input.txt in the same folder where the executed file exists, but there was an error.
input = fopen ("b:input.txt", "r");
Next I copied the address from the property of the text file and entered
but this didn't seem to work either.
input = fopen ("C:\Programming\2013-06-06\2013-06-06\input.txt", "r");
Where am I supposed to store my files, and how am I suppose to locate them?
June 10th, 2013, 04:34 PM
In order to use backslashes in a path you must use \\ for each \.
I ♥ ManiacDan & requinix
This is a sig, and not necessarily
a comment on the OP:
don't be a help vampire
June 10th, 2013, 04:37 PM
In C/C++ the '\' character is considered the escape character, so to use this character in a string you need two for each occurrence.
Also note that using the "r" open command the file must exist, it will not be created if it doesn't exist.
input = fopen ("C:\\Programming\\2013-06-06\\2013-06-06\\input.txt", "r");
Also the working directory is not always located in the directory where the executable is located. If you're running the program thru an IDE the working directory is often where the project file is located.
June 10th, 2013, 04:39 PM
Thank you, I got it fixed now.
I'll keep that in mind.