Solved Segmentation Fault, by changing from stack allocation to heap allocation