fopen fails in special condition (windows+eclipse cdt+mingw)

397 views Asked by At

I'd like to develop a simple windows application with MingW + Eclipse on Windows.

But I can't debug program with GDB because if I run the program in debug mode, fopen always fails (returns NULL pointer).

FILE* fp = fopen(filename, "r");

Does anyone know how to avoid such a phenomena?

case 1) ran program normally (not debug mode)

works fine.

case 2) ran program using gdb (not using eclipse CDT)

works fine.

case 3) ran program using eclipse CDT and gdb

doesn't work. (fopen always returns NULL pointer)


gcc 4.6.2 gdb 7.6.1 eclipse 4.6.1 (neon) Windows7 Enterprise (SP1) 64bit edition


Thanks for many useful advices! At first I don't know perror function,, Here is my test codes.

    FILE* fp = fopen(filename, "r");
    char lineBuffer[256];
    if (fp) {
        while (fgets(lineBuffer, 256, fp) != NULL) {
            doSomething(lineBuffer);
        }
        fclose(fp);
    }
    else {
        perror("error ");
    }

filename are passed by argv/argc.

Firstly I used relative path and perror result is following (someone.txt)

error : No such file or directory

Secondery I used absolute path and perror result is following.(D:\someone.txt)

error : Invalid argument
0

There are 0 answers