Reputation: 399
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);
Upvotes: 0
Views: 2861
Reputation: 1061
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){...}
Upvotes: 3
Reputation: 1481
Try printing the error using
printf ("Error opening file : %s\n",strerror(errno));
Upvotes: 1
Reputation: 6070
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")
Upvotes: 0