Search code examples
ctypedef

How to return my "theMove" and solve the writing rights problem


I am trying to do a chessboard with movements, and I cannot manage to get the coordinates of the 2 chess pieces to move:

void saisie_deplacement(int color)
{
    char lettre[8]={'A','B','C','D','E','F','G','H'};
    deplacement theMove;

    char L,L1;
    int x,x1,y,y1;

    printf("\n\n\nType the 1st piece's Letter.\n");
    scanf(" %c", &L);

    x = L;
    x = x-'A';
    printf("\n%i\n", x);

    printf("\nType the 1st piece figure\n");
    scanf(" %i", &y);

    printf("\nType the 2nd piece letter\n");
    scanf(" %c", &L1);

    x1= L1;
    x1=x1 - 'A';
    printf("\n%i\n", x1);

    printf("\n\n\nType the 2nd piece figure\n");
    scanf(" %i", &y1);

    theMove.depart.ligne = x;
    theMove.depart.colonne = y;
    theMove.arrivee.ligne = x1;
    theMove.arrivee.colonne = y1;

}

I don't know how I can return theMove.

Otherwise, CodeBlocks tells me this :

||=== Build file: "no target" in "no project" (compiler: unknown) ===|
ld.exe||cannot open output file C:\Users\dissi\Desktop\C\tpregled.exe Permission denied|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

Then i can't compile without changing the .exe file name. It seems like my program stays open in ntoskrnl.exe

Would you guys know what i should do about it ? :)


Solution

  • To return theMove, do as follows:

    First declare that the function will return it:

    deplacement saisie_deplacement(int color) {
    

    (void means it will return nothing, but you do want it to return something of type deplacement)

    Then after having filled in all the fields, tell the function to return the variable of type deplacement:

        return theMove;
    }