Compiled successfully but segmentation fault on run