Can't get file content with fopen()

This is strange
I have this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
long len;
FILE *fp;
if ((fp = fopen("data/settings.stg", "r")) != NULL) {
    fseek(fp, 0, SEEK_END);
    len = ftell(fp);
    fseek(fp, 0, SEEK_SET);
    char* content = (char *)malloc(len);
    fread(content, len, 1, fp);
    fclose(fp);
    char buff[32];
    itoa(len, buff, 10);
    MessageBox(NULL, buff, "Content length", NULL);  //Shows me the file length
} else {
    MessageBox(NULL, "Error", "Error", NULL);
}


The execution of the application gives me the error message. I have another source code that uses exactly the same code for opening a file and getting its content and it works. The difference is that the other one opens the file from the same directory as the executable and by using an OPENFILENAME dialog. I moved the file "settings.stg" inside the folder of the executable but the same ocurrs. What could the problem be?
Last edited on
Solved, I need the absolute path
Topic archived. No new replies allowed.