0

Working on problem set 4- Recover but keep getting Segmentation Fault. Tried valgrind too, but could not figure it out.

Could anyone kindly anyone look into the code and tell me where does the problem lie?

code link strong text- https://github.com/me50/ayushm2003/blob/fb12d1a6bfb0d579794028ea66822564eaf11656/recover.c

Thanks to anyone who devotes their time.

1
  • bad link. or no permissions for others to access it. can you fix it? – Cliff B Apr 6 '20 at 19:38
1

It's more important that you know how to locate seg faults. This is a very common defect and if you can't locate seg faults, you will be severely handicapped.

There are two common ways. First, insert strategic unique printf statements. A seg fault will occur after the last executed printf and before the first non-executed printf. Just keep moving them closer together until you bracket the failing code with printf statements just before and after it!

Second, you can run the code in a debugger and step through until it fails. The problem here is that sometimes, the mere act of running the code in the debugger can mask the seg fault. Then, it's time to fall back to the first method.

So, with that in mind, it's time to take another crack at finding your seg fault. Once you find it, then we can discuss what is actually causing it, assuming you can't figure it out. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .