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命令
可以查看进程意外退出前函数调用的堆栈