我正在尝试将名称分配给 TCP 服务器中的客户端,但该strcpy()功能给了我一个分段错误。
struct clients{
int client_fd;
char* name;
struct clients* next;
}
struct clients* first;
first->client_fd = 1;
first->name = NULL;
memset(&first->name, 0, sizeof(first->name));
first->name = (char*)malloc(100*sizeof(char));
strcpy(first->name, "User");
first->next = NULL;
Run Code Online (Sandbox Code Playgroud)