Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fopen and windows

This is the first time I'm coding C in Windows and a weird bug is driving me crazy.

I'm trying to open a .txt file using fopen, and it keeps giving me the "file doesn't exist" error (it also gave me the "no permission" error, once).

My code is as follows (doesn't get any simpler than that):

FILE *file;

if((file=fopen("C:\\Users\\ste\\Desktop\\file.txt", "r"))==NULL) 
{
    printf("Cannot open file.\n");
    puts(strerror(errno));

    getchar();
    exit(1);
}

Am I missing something here? Thanks in advance!

like image 823
STE Avatar asked Dec 01 '22 23:12

STE


1 Answers

I bet you have the Windows "hide extensions" bugfeature turned on. So the file which is really called "file.txt" appears in your Explorer as "file". And if it appeared to be "file.txt" in the Explorer, it would have to be named "file.txt.txt" on the hard drive.

like image 198
AShelly Avatar answered Dec 14 '22 05:12

AShelly