当我尝试在Eclipse CDT中运行我的程序时,我的可执行文件停止运行

时间:2015-10-13 01:28:36

标签: c eclipse linker execution eclipse-cdt

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

enter image description here

现在网上有一些资源,包括:

  1. This SO帖子,其中有一个答案尚未被接受。答案是无效的,因为我对我的程序没有任何论据。

  2. This论坛在Eclipse社区论坛上发布。这有一些很好的建议,特别是与改变MinGW的链接器标志有关的建议。但是,这适用于C ++程序而不适用于C程序。 This也是一个处理相同问题的帖子,但对C ++来说也是如此。

  3. 这就是为什么我目前正在为我的Eclipse CDT上的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");
    }
    

    我的answer()程序如下:

    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;
    }
    

1 个答案:

答案 0 :(得分:0)

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

https://www.youtube.com/watch?v=azInZkPP56Q

但即使在本教程之后你也很难让你的debuger工作(因为有时它取决于你的Eclipse,你的编译器和其他东西的安装方式),你可以尝试将大部分代码放在注释中,看看是否问题消失了。并逐渐减少您发表评论的代码量。当bug重新出现时,这意味着它最近在你删除评论的部分内部。

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