URL: https://linuxfr.org/forums/programmation-c--2/posts/probleme-de-pointeur Title: Problème de pointeur ? Authors: sosor Date: 2014年10月30日T12:16:58+01:00 License: CC By-SA Tags: Score: 0 Bonjour, je suis nouvelle en programmation et on doit faire un projet dont le but des créer un jeux du style de CandyCrush. J'ai réussi à créer la matrice des items, a faire déplacer le curseur dans la matrice, à faire changer deux case (même s'il y a un petit problème: je dois appuyer sur n'importe qu'elle touche avant de saisir la case avec laquelle je veux inter-changer), j'ai un petit problème avec le compteur du nombre de coup, et le Big problème c'est dans mon sous programme faireTomber, je souhaite remplir les trous en faisant tomber les lettres mais il plante quand je compile. Merci pour votre aide ! ```ruby void gotoligcol( int lig, int col ) { COORD mycoord; mycoord.X = col; mycoord.Y = lig; SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), mycoord ); } void swap(int*pt1,int*pt2) { int tempon; tempon = *pt1; *pt1 = *pt2; *pt2 = tempon; } void echangercoo(int lig,int col,int mat2[10][15]) { int nbcoup; nbcoup=5; int X=getch(); X=getch(); do { switch (X) { case '2': if (lig<13) gotoligcol(lig,col); swap(&mat2[lig][col],&mat2[lig+1][col]); printf("%d",nbcoup); --nbcoup; gotoligcol(lig,col); printf("%c",mat2[lig][col]); gotoligcol(lig+1,col); printf("%c",mat2[lig+1][col]); gotoligcol(lig,col); gotoligcol(13,1); printf("Il vous reste %d coups ",nbcoup); break; case '4': if (col>1) gotoligcol(lig,col); swap(&mat2[lig][col],&mat2[lig][col-1]); gotoligcol(lig,col); printf("%c",mat2[lig][col]); gotoligcol(lig,col-1); printf("%c",mat2[lig][col-1]); gotoligcol(lig,col); nbcoup=nbcoup-1; gotoligcol(13,1); printf("Il vous reste %d coup",nbcoup); break; case '6': if(col<8) gotoligcol(lig,col); swap(&mat2[lig][col],&mat2[lig][col+1]); gotoligcol(lig,col); printf("%c",mat2[lig][col]); gotoligcol(lig,col+1); printf("%c",mat2[lig][col+1]); gotoligcol(lig,col); nbcoup=nbcoup-1; gotoligcol(13,1); printf("Il vous reste %d coup",nbcoup); break; case '8': if (lig>1) gotoligcol(lig,col); swap(&mat2[lig][col],&mat2[lig-1][col]); gotoligcol(lig,col); printf("%c",mat2[lig][col]); gotoligcol(lig-1,col); printf("%c",mat2[lig-1][col]); gotoligcol(lig,col); nbcoup=nbcoup-1; gotoligcol(13,1); printf("Il vous reste %d coup",nbcoup); break; case ' ': gotoligcol(lig,col); printf("%c", mat2[lig][col]); gotoligcol(13,1); printf("Il vous reste %d coup",nbcoup); break; } } while(nbcoup!=0); if(nbcoup==0) { printf("\n Vous avez perdu !"); } } void curseur(int*lig, int*col, int mat3[10][15]) { int choix=getch(); int t=0; do { choix=getch(); switch(choix) { case '2': if(*lig<9) *lig=*lig+1; gotoligcol(*lig,*col); break; case '4': if(*col>0) *col=*col-1; gotoligcol(*lig,*col); break; case '6': if(*col<14) *col=*col+1; gotoligcol(*lig,*col); break; case '8': if(*lig>0) *lig=*lig-1; gotoligcol(*lig,*col); break; case ' ': gotoligcol(*lig,*col); mat3[*lig][*col]=mat3[*lig][*col]+32; printf("%c",mat3[*lig][*col]); mat3[*lig][*col]=mat3[*lig][*col]-32; echangercoo(*lig,*col,mat3); break; } } while (t==0); } void supression(int mat[10][15]) //Supprimer 3 items identiques cote à cote { int i,j; for(i=0; i<10; i++) { for(j=0 ; j<15; j++) { if((mat[i][j]==mat[i][j+1])&&(mat[i][j]==mat[i][j+2])) { mat[i][j]=' '; gotoligcol(i,j); printf("%c",mat[i][j]); mat[i][j+1]=' '; gotoligcol(i,j+1); printf("%c",mat[i][j+1]); mat[i][j+2]=' '; gotoligcol(i,j+2); printf("%c",mat[i][j+2]); } else { if ((mat[i][j]==mat[i+1][j])&&(mat[i][j]==mat[i+2][j])) { mat[i][j]=' '; gotoligcol(i,j); printf("%c",mat[i][j]); mat[i+1][j]=' '; gotoligcol(i+1,j); printf("%c",mat[i+1][j]); mat[i+2][j]=' '; gotoligcol(i+2,j); printf("%c",mat[i+2][j]); } else; } } } } void faireTomber(int mat4[10][15]) { int i,j,a; a=0; for (i=0; i<9; i++) { for(j=0; j<14; j++) { if (mat4[i][j]==' ') { do { mat4[i-a][j]=mat4[i-a+1][j]; a++; gotoligcol(i-a,j); printf("%c",mat4[i-a][j]); }while(a!=9-i); } } } } int main() { int mat[10][15]; int ligne=0,colonne=0; matrice(mat); supression(mat); faireTomber(mat); // gotoligcol(0,0); //afficherMatrice(mat); curseur(&ligne,&colonne,mat); return 0; } ```