首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

linux c 段异常 奇怪

2012-06-22 
linux c 段错误 奇怪[codeC/C++][/code]while(i6){gcvt(temp[i], n, str)strcat(head,str)strcat(head

linux c 段错误 奇怪
[code=C/C++][/code]
while(i<6)
  {
  gcvt(temp[i], n, str);
  strcat(head,str); 
  strcat(head,"}"); 
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, head);
  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  // res = curl_easy_perform(curl);
   
   
  /* redo request with our own custom Accept: */
  res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
  res = curl_easy_perform(curl);
  sscanf(head, "%[^0-9]", head);
  sleep(3);
  i++;
  if(i==5)
  i=0;
  }

while循环是main函数的,现象是可以执行6次循环,然后再从i==0是,就显示段错误了
  char head[10]="{\"value\":";
  char str[5];
head和str定义如上,奇怪了。

[解决办法]
你head里面已经有9个字符了,再加个尾0,都已经没空间。
再strcat一下,str中只要有2个字符以上都会挂啊。
[解决办法]
strcat()写越界
[解决办法]
进程意外退出会在当前目录下产生形如‘core.数字’的文件比如‘core.1234’
使用命令
gdb 运行程序名 core.数字
进入gdb然后使用bt命令
可以查看进程意外退出前函数调用的堆栈

热点排行