like fgets but for null-terminated strings