当我试图在EclipseCDT中运行我的程序时,我的可执行文件停止运行

当我试图在EclipseCDT中运行我的程序时,我的可执行文件停止运行,c,eclipse,linker,execution,eclipse-cdt,C,Eclipse,Linker,Execution,Eclipse Cdt,在我构建了我的项目之后,我似乎收到了这样一条信息:我的程序Cyber Dojo 1已经停止工作。如下所示: 现在有一些在线资源,包括: 所以这篇文章有一个答案还没有被接受。答案是无效的,因为我的程序没有任何参数 论坛将自己发布在Eclipse社区论坛上。这有一些很好的建议,特别是关于更改MinGW的链接器标志的建议。但是,这将应用于C++程序而不是C程序。也是一个处理相同问题的帖子,但是对于C++来说也是如此。p> 这就是为什么我目前正在为EclipseCDT上的C程序寻找这个问题的解决方案 这

在我构建了我的项目之后,我似乎收到了这样一条信息:我的程序Cyber Dojo 1已经停止工作。如下所示:

现在有一些在线资源,包括:

所以这篇文章有一个答案还没有被接受。答案是无效的,因为我的程序没有任何参数

论坛将自己发布在Eclipse社区论坛上。这有一些很好的建议,特别是关于更改MinGW的链接器标志的建议。但是,这将应用于C++程序而不是C程序。也是一个处理相同问题的帖子,但是对于C++来说也是如此。p> 这就是为什么我目前正在为EclipseCDT上的C程序寻找这个问题的解决方案

这是我的密码:

     //Checking number as input
     static void isNotValidCharacter1(void)
     {
        assert(answer('3') == NULL);
     }

//Checking special character
static void isNotValidCharacter2(void)
{
    assert(answer('!') == NULL);
}

//Checking lowercase letter
static void isNotValidCharacter3(void)
{
    assert(answer('c') == NULL);
}


static void validCharacter(char **sample_answer)
{
    int i, j;
    for (i = 1; i < 11; i++) {
        for (j = 1; j < 11; j++) {
            assert((answer('F'))[i][j] == sample_answer[i][j]);
        }
    }
}

//Random Number Corner Checks Follow:

// Randomly creates a number/ character and checks the leftmost and rightmost corner characters
// as the character itself

static char psuedoRandomNumberGeneratedCharacterCheck1(void)
{
    // Creating the random number between 65 and 90
    int rn;
    srand(time(NULL));
    rn = (rand() % 25) + 65;
    int distA = rn - 65;

    //converting it to a character
    char c_rn = (char)rn;
    //checking the leftmost and rightmost corner characters
    assert(answer(rn)[distA][0] == c_rn);
    assert(answer(rn)[distA][distA*2] == c_rn);
    return c_rn;
}

// Randomly creates a number/ characters and the checks the uppermost and lowermost corner characters
// corners as 'A'

static char psuedoRandomNumberGeneratedCharacterCheck2(void)
{
    // Creating the random number between 65 and 90
    int rn;
    srand(time(NULL));
    rn = (rand() % 25) + 65;
    int distA = rn - 65;

    //converting it to a character
    char c_rn = (char)rn;
    //checking the uppermost and lowermost corner characters
    assert(answer(rn)[0][distA] == 'A');
    assert(answer(rn)[distA*2][distA] == 'A');
    return c_rn;
}

static void validCharacterA(void)
{
    char **aDiamond = answer('A');
    aDiamond[0][0] = 'A';
}

int main(void)
{
    //Not valid character tests
    isNotValidCharacter1();
    puts("Number not accepted");
    puts("special pause for debugging");
    isNotValidCharacter2();
    puts("Special Character not accepted");
    isNotValidCharacter3();
    puts("lowercase not accepted");

    //Psuedorandom Tests

    char prc1 = psuedoRandomNumberGeneratedCharacterCheck1();
    printf("random character '%c' chosen and the leftmost and rightmost corner characters", prc1);
    char prc2 = psuedoRandomNumberGeneratedCharacterCheck2();
    printf("random character '%c' chosen and the leftmost and rightmost corner characters", prc2);

    // Acid Test for the letter 'F'

    //Square of 11 letters declared
    char **Fanswer = malloc(11 * sizeof(*Fanswer));
    int i;
    for (i =0; i  <11; i++) {
        Fanswer[i] = malloc(11 * sizeof(char));
    }

    strcpy( Fanswer[0], "     A     ");
    strcpy( Fanswer[1], "    B B    ");
    strcpy( Fanswer[2], "   C   C   ");
    strcpy( Fanswer[3], "  D     D  ");
    strcpy( Fanswer[4], " E       E ");
    strcpy( Fanswer[5], "F         F");
    strcpy( Fanswer[6], " E       E ");
    strcpy( Fanswer[7], "  D     D  ");
    strcpy( Fanswer[8], "   C   C   ");
    strcpy( Fanswer[9], "    B B    ");
    strcpy(Fanswer[10], "     A     ");

    validCharacter(Fanswer);
    puts("answer for F is correct");

    validCharacterA();
puts("Answer for A is correct");

    //All tests have passed and the end of the program
    puts("All tests passed");
}

如果您是Eclipse的初学者,并且不知道如何使用调试器,那么可以参考一些教程

但即使在本教程之后,您也很难让调试程序正常工作,因为有时这取决于Eclipse、编译器和其他东西的安装方式,您可以尝试将大部分代码放在注释中,看看问题是否消失。一点一点地减少你在评论中的代码量。当这个错误再次出现时,它意味着它在你最近删除评论的部分的某个地方


最后一种方法不是调试程序的最佳方法,但对初学者来说很有用,如果您使用调试器有困难,可以为您提供另一种选择。

请发布相关程序,您的所有帖子都是无用的。您的程序显然正在崩溃,但无法猜测原因,除非周围有人是通灵者。@iharob我的构建完全没有错误,我也不知道我应该在这里发布程序的哪一部分。这与构建过程无关。您可以轻松地编写和编译代码,而不会出现错误或警告,并且仍然会崩溃。示例char*溢出;溢出=malloc100;溢出[100]='\0';就在那里,它可能会坠毁。它会导致未定义的行为,可能是在内存区域中读取,从而使系统发出SIGSEGV信号,指示内存访问分段错误无效。@iharob让我检查一个简单的helloworld程序是否可以工作,如果可以,我将发布我的程序中一些更重要的malloc,发布一个复制这种行为的程序。行!一旦我尝试了调试器,我就会回到这个答案上来。
char** answer(char c)
{

    if (check(c)) {
        printf("\n");
    } else {
        printf("Not a valid character\n");
        return NULL;
    }


    //--------------------------------------------------------------------------------------------------------
    //   Preprocessing
    //--------------------------------------------------------------------------------------------------------

    //processing declarations
    int ascii = (int)c;
    int distA = ascii - 'A';

    //Number of Rows and Columns
    int n = ( distA * 2 ) + 1;

    //Declare the column of pointers
    char **diamond = malloc(n * sizeof(*diamond));

    //Declare the row of characters
    // 2D array declared here to save on computation in situations where characters are not valid
    int i;
    for (i=0; i<n; i++) {
            diamond[i] = malloc(n * sizeof(char));
    }

    //--------------------------------------------------------------------------------------------------
    //   Processing
    //--------------------------------------------------------------------------------------------------

    //Fill in the Array
    if (n == 1) {
        diamond[0][0] = c;
    } else {
        diamond[distA][0] = c;
        diamond[distA][distA*2] = c;
        for (i = 1; i <= distA; i++) {
            diamond[distA-i][i] = (char)(ascii - i);
            diamond[distA-i][(distA*2)-i] = (char)(ascii - i);
            diamond[distA+i][i] = (char)(ascii - i);
            diamond[distA+i][(distA*2)-i] = (char)(ascii - i);
        }
    }

    //-------------------------------------------------------------------------------------------------
    //   Postprocessing
    //---------------------------------------------------------------------------
    return diamond;
}