小编tar*_*run的帖子

简单字符串操作中的分段错误

该程序在执行时给出了分段错误.我该如何解决这个问题?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
{
  int bufsize = 1024;
  char *buf;
  char *msg="GET /dumprequest HTTP/1.1";
  memset (buf,0, bufsize);
  strcpy(buf,msg);
  puts(buf);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

c gcc segmentation-fault

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

标签 统计

c ×1

gcc ×1

segmentation-fault ×1