Skip to content
Sign upLog in
← Back to Community

How to fix segmentation fault

Profile icon
dnielletorres

This is my first attempt at C and I am having trouble with this specific error and I don't know where to fix it.

Voters
Profile icon
JSANS221
Profile icon
LoginTMExperime
Profile icon
CaptainRomu
Profile icon
iciarmanueco1
Profile icon
AasthaAgarwal1
Profile icon
ac2993
Profile icon
TRAMPPP
Profile icon
0177jaw
Profile icon
FaroukOmer
Profile icon
yeoyx23
Comments
hotnewtop
Profile icon
SyedShamsuddin

Factorials are hard to compute especially by using recursion , I believe changing the return value may increase your range of computability but otherwise stack overflow will lead to segmentation failure

Profile icon
Stormcrest

make the unsigned int into a regular int and it will work

Profile icon
Keracz

try first compile program, use gcc file1, file2 and ./a.out its work for me. i have the same problem when run program by press run button

Profile icon
Highwayman

It seems to be something about your factorial function. It’s a recursive function, so I’d think it’s a stack overflow or something but that doesn’t make sense because when I tested it with 0, it still crashed. Good luck I guess?

Profile icon
[deleted]

Try checking your arrays
A segmentation fault (from what I understand of) is ussualy caused by something wrong with the memory of the program
like int array[1] = {2}, and you calling array[420]