C 线程:信号SIGABRT(lldb)和程序以退出代码-1结束

C 线程:信号SIGABRT(lldb)和程序以退出代码-1结束,c,xcode,multithreading,printf,sigabrt,C,Xcode,Multithreading,Printf,Sigabrt,程序停止,线程出现在sprint的行中: sprintf(x,"%d",x2); 这不是将int x2转换为stringx的最佳方法吗 int check(int n,char [8]); int main(){ char x[8]="0"; int N,x2; scanf("%d",&N); while(strlen(x)<9){ if(check(N,x)) printf("%s\n",x); x2=ato

程序停止,线程出现在sprint的行中:

sprintf(x,"%d",x2);
这不是将int x2转换为stringx的最佳方法吗

int check(int n,char [8]);

int main(){
    char x[8]="0";
     int N,x2;

    scanf("%d",&N);
    while(strlen(x)<9){
        if(check(N,x)) printf("%s\n",x);
        x2=atoi(x);
        x2++;
        sprintf(x,"%d",x2);
        }
    return 0;
    }


int check(int n,char x[8]){
    int l,i,y,count;
    l=strlen(x);
    y=atoi(x);
    count=0;
    for(i=0;i<l;i++){
        count=count+pow((x[i]-'0'),n);
    }
    if(count==y) return 1;
    else return 0; }

如果您已经发布了编译行+实际编译的代码,即包含了正确的头,那么它会更有用!。当移动到数组大小为10时,虽然需要一段时间才能退出,但效果良好!:

修改后的代码:

C:\...>cat main.c

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

int check(int n,char [10]);

int main(){
    char x[10]="0";
     int N,x2;

    scanf("%d",&N);
    while(strlen(x)<9){
        if(check(N,x)) printf("%s\n",x);
        x2=atoi(x);
        x2++;
        sprintf(x,"%d",x2);
        }
    return 0;
    }


int check(int n,char x[10]){
    int l,i,y,count;
    l=strlen(x);
    y=atoi(x);
    count=0;
    for(i=0;i<l;i++){
        count=count+pow((x[i]-'0'),n);
    }
    if(count==y) return 1;
    else return 0; }
调试:

C:\...>gdb a.exe
GNU gdb (GDB) 7.6.2
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-w64-mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from C:\...\a.exe...done.
(gdb) run
Starting program: C:\.../a.exe
[New Thread 8396.0x199c]
3
0
1
153
370
371
407
[Inferior 1 (process 8396) exited normally]
(gdb) quit

世界上一切都好!:D

charx[8]=0;而whilesrlenx,但即使char x[9]=0,它也将是同一个线程并退出-1,因为循环在终止之前打印一次长度为9的字符串。。。当char x[10]=0时它还会崩溃吗?是的,这是一样的!SIGABRT线程可能是用于Sprint的。我检测到***堆栈崩溃***:./foo在程序结束时终止,这在将所有字符[8]转换为字符[10]时是固定的。你是对的,但确实需要一段时间,所以我将尝试不使用任何字符串,而只使用整数,希望它能解决时间问题:
C:\...>gdb a.exe
GNU gdb (GDB) 7.6.2
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-w64-mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from C:\...\a.exe...done.
(gdb) run
Starting program: C:\.../a.exe
[New Thread 8396.0x199c]
3
0
1
153
370
371
407
[Inferior 1 (process 8396) exited normally]
(gdb) quit