NUGA
NUGA

Reputation: 335

SIGSEV while using DDD (Data Display Debugger)

It's my first time using DDD and i'm pretty inexperienced with the subject matter in question (c in unix environment) so i might be overlooking something. I'm receiving a segmentation fault when i try to fscanf from a file, which doesn't occur in a normal gcc compilation. The function is the following:

void read_config(){
    FILE *fp;
    fp = fopen("config.txt","r");
    fscanf(fp,"TRIAGE=%dDOCTORS=%dSHIFT_LENGTH=%dMQ_MAX=%d ",&data.triage,&data.doctors,&data.shift,&data.mq_max);
}

and after reading the fscanf line it give the following message in DDD:

Program received signal SIGSEGV, Segmentation fault. 0xb7e58e1e in __isoc99_fscanf () from /lib/i386-linux-gnu/lib.so.6

I can't figure out what might be causing this issue. Thanks in advance!

Upvotes: 0

Views: 245

Answers (1)

Employed Russian
Employed Russian

Reputation: 213526

I can't figure out what might be causing this issue.

Look in the debugger at the value of fp. It will be NULL.

You should always check return value of every system function you call.

the file is in the same directory as the executable

That doesn't matter. What matters is what is your current directory when you are calling fopen.

Unless you instructed DDD to change to the directory where config.txt resides, chances are DDD is running from some other directory.

Upvotes: 0

Related Questions