PDA

View Full Version : Segmentation fault error!!



K-Z
January 25th, 2010, 09:56 PM
Done...

lisati
January 25th, 2010, 09:59 PM
First thought: is the fopen() working?

dwhitney67
January 25th, 2010, 10:49 PM
This little puppy needs to point to some valid memory location within the program space; not just dangle.


char *lgfle1;

K-Z
January 26th, 2010, 07:43 PM
First thought: is the fopen() working?
yup....tht has been tested...

K-Z
January 26th, 2010, 07:45 PM
This little puppy needs to point to some valid memory location within the program space; not just dangle.


char *lgfle1;

lgfle is the logfile containing output of netstat -p command that would be passed from the shell...

dwhitney67
January 26th, 2010, 07:46 PM
lgfle is the logfile containing output of netstat -p command that would be passed from the shell...

It's use in the fscanf() is causing your app to "barf".

ibuclaw
January 26th, 2010, 08:00 PM
lgfle is the logfile containing output of netstat -p command that would be passed from the shell...

What dwhitney means is that lgfle1 = (null);

fscanf() runs successfully, but never passes any data to lgfile1 because it is not pointing to any memory.

edit:
Also, correct me if I'm wrong, but wouldn't fscanf only return the first word in the logfile? As it should stop after the first bit of whitespace is found.

Regards
Iain

dwhitney67
January 26th, 2010, 08:13 PM
What dwhitney means is that lgfle1 = (null);

There's no guarantee that this is the case; lgfle1 could be pointing anywhere. I bet it's pointing to an address (perhaps 0x00) that's outside the program space, thus causing the app to crash.

K-Z
January 28th, 2010, 10:37 AM
I have sorted out the problem. Actually we would have to use fgetc instead of fscanf to store complete data of file in lgfle.