I've changed the code in the way you instructed, i get same segmentation fault.