Bonjour,
Je souhaite faire passer un tableau a 2 dimensions en parametre d'une fonction.
Je ne comprend pas pourquoi le code ci dessous ne marche pas, d'après les forums que j'ai lus ca devrait marcher.
(Je ne dois utiliser l'allocation dynamque)
Si quelqu'un peu m'éclairer.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 #include <stdio.h> #include <stdlib.h> #include <string.h> void display_grid(int **grid); int width = 10; int height =20; int main() { int i,j; int grid[width][height]; for(i=0;i<height;i++) { for(j=0;j<width;j++) { grid[j][i] = i+j; //fill up the grid with * } } display_grid(grid[][height]) return 0; } void display_grid(int **grid) //display the grid { int i,j; for(i=0;i<height;i++) { printf("|"); for(j=0;j<width;j++) { printf("%d",grid[j][i]); } printf("|\n"); } }
Merci
Partager