How do you run the file? Is it from the command line or from the IDE? The directory where your executable is located is not necessarily your working directory.
Try using the full path name in fopen and see if it fixes it. If so, then the problem will be as described.
For example:
file = fopen("c:\\MyDirectory\\TestFile1.txt", "r"); file = fopen("/full/path/to/TestFile1.txt", "r");
Or open a command window and go to the directory where your executable is located, then run it manually.
Aside, you can insert a simple one (for Windows or Linux / UNIX / BSD / etc respectively):
system ("cd") system("pwd")
before fopen to show which directory you are in.
paxdiablo
source share