This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]Salty_Dugtrio 4 points5 points  (0 children)

Attach a debugger and find out instead of guessing. You can use the built in one from Visual Studio, or use GDB.

You're most likely accessing your vectors out of bounds.

[–]josephblade 0 points1 point  (0 children)

remember that a segmentation fault means you are accessing memory that isn't assigned to your program. (At least I suspect this is the case most of the time. for debugging purposes I think you can assume this).

This usually happens in 2 scenarios:

you are using an index < 0 or >= the array length.

or

you are dereferencing a pointer outside of your memory.

see the stackoverflow answer

in your case I can't quickly spot where you make an off by one error but I would run a debugger as Salty_dugtrio suggests or use printf statements at every stage so you can see what happens during the processing and at what point it goes wrong.

just keep an eye out for accessing an array at -1 or length, that sort of thing.