Seg faults are not terribly difficult to trace if you know how to use a debugger. Learn to use one, it will save you hours of headache.

Your code is rife with potential seg faults and other...