Use strdup() instead of strncpy().