小编NNN*_*NNN的帖子

c 中的 strcpy() 给了我分段错误

我正在尝试将名称分配给 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)

c segmentation-fault

1
推荐指数
1
解决办法
73
查看次数

标签 统计

c ×1

segmentation-fault ×1