Error in C programming in Linux: segmentation fault?
hajjizadeh2002
2007-05-10 17:19:54 UTC
I compile the program with no errors, but when running it give me "segmentation error", help me please.
Three answers:
Ken H
2007-05-10 17:27:24 UTC
A segmentation error is caused when the kernel detects an attempt to access memory they program is not allowed to access, and sends a segfault signal, which normally kills the offending process.
Use a debugger (or print statements) to trace where the program is attempting this illegal access, and work from there.
Note, in C, these are usually cause by a pointer problem or stack overflow.
2007-05-10 18:41:43 UTC
If you intend learning C you will eventually become immune to all the segmentation faults you will get! Segmentation faults are most of the time caused by incorrect pointer referencing such as below:
{ int* a;
*a= 3;
}
If you are new to C and want I would suggest you read this guide http://beej.us/guide/bgc/
It is very very helpful
lolita
2016-11-27 06:34:58 UTC
can no longer tell for specific considering you probably did no longer supply the code for getgrent(), yet i could suspect it is not returning a valid pointer for g and/or no longer forming the gr_name string remarkable (no terminating 0 maximum possibly). desire that helps. till getgrent() is a Linux gadget function. Then I dunno. i'm a abode windows guy. CORRECTION: your statement of substantial() and use of arg are the two incorrect. they ought to be: int substantial( int argc, char * argv[] ) and if ( strcmp( argv[i], "-u" ) == 0 // Gotta selection i from 0 to argc - a million, that's the count style of the entries in argv[]. desire that helps.
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.