fixed segmentation fault with fgets()