Search code examples
ceclipselinkerexecutioneclipse-cdt

My executable stops running when I try to runmy program in Eclipse CDT


After I build my project, I seem to be getting this message where it says that my program Cyber Dojo 1 has stopped working. This is shown below:

enter image description here

Now there are a few resources online, including:

  1. This SO post, which has one answer that has not been accepted. The answer is not valid, as I do not have any arguments for my program.

  2. This forum post itself on the Eclipse Community Forums. This has a few good suggestions, especially the one that relates to changing MinGW's linker flags. However, this would apply to a C++ program and not a C program. This is also a post that deals with the same problem, but once again, for C++.

And that is why I am currently looking for a solution for this problem for a C program on my Eclipse CDT.


Here is my code:

     //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");
}

And my program for answer() is as follows:

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

Solution

  • If you are a beginer with Eclipse and you don't know how to use a debugger, you can look some tutorial.

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

    But even after this tutorial you have difficulty to making your debuger works (because sometimes it depends how installed your Eclipse, your compiler and other things), you can try to put a big part of your code in comment and see if the problem is gone. And little by little reduce the amount of code you put in comment. When the bug reapear it means it's somewhere inside the part you removed the comment recently.

    The last method is not the best way to debug your program but can be usefull for beginners and give you another alternative if you have difficulty to use your debugger.