Getting segfault in the C code. Working to find out why