char buf[10]; strncpy(buf, data, sizeof(buf)); buf[sizeof(buf) - 1] = '\0';