Segfault in libc error 5

used Ivan’s solution from this post