C function like fgets but for null terminated strings