When you get a segmentation fault, it's likely that it's because you try to reference the memory at where you should not have, i.e., you access the array at the index that is out of bound.
One of the tools that can help you is to use gdb.
This is an example of how to use gdb. Assume that '%' is your prompt on your CAEN account.


%g++ -g -o proj2 proj2.cpp 
%gdb proj2

At the gdb session (assume that (gdb) is the gdb prompt), you then type


(gdb) run
If there's the segmentation fault, you then type
(gdb) where
It will give you the codes where the segmentation fault occurs.
Then type
(gdb) quit
to exit the program.
For more information about how to use gdb, go to Debugging with GDB