July 1, 2007
Error in C programming in Linux: segmentation fault?
I compile the program with no errors, but when running it give me "segmentation error", help me please.
- 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.
- 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























