Working first code, seg fault second