myfile= fopen("IN.txt",r);
schould be
myfile = fopen("IN.txt","r");
and make sure your filesystem is as case(in)sensitive as your filename suggests (so "IN.txt" is on UN*X different file to "in.txt")
Question
What can be wrong with my code below that it never opens the file. I've also tried with absolute file path but that doesn't helped me, I know physically that the file is there.
FILE *myfile;
myfile= fopen("IN.txt",r);
if (myfile != NULL)
{
while ( fscanf(myfile,"%lf",&test) !=eof )
{
printf("%f",test);
printf("\n");
}
}
fclose(myfile);
Solution 3
myfile= fopen("IN.txt",r);
schould be
myfile = fopen("IN.txt","r");
and make sure your filesystem is as case(in)sensitive as your filename suggests (so "IN.txt" is on UN*X different file to "in.txt")
OTHER TIPS
Maybe you want to do like this:
myfile= fopen("IN.txt","r");
This is because the second argument is of const char* type
And here:
while ( fscanf(myfile,"%lf",&test) !=EOF )
(C is case sensitive).
EDIT: And I'd like to suggest to use something like:
while ( (fscanf(myfile, "%lf", &test)) > 0){...}
Try printing the error using
printf ("Error opening file : %s\n",strerror(errno));