error: incompatible types in assignment
Bonjour à tous,
j'ai cette erreur que je ne parviens à comprendre compte tenu de mon code :
Code:
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 40 41 42 43 44 45
| #include <stdio.h>
#include <stdlib.h>
#define TAILLE_L 30
#define TAILLE_C 10
int main(int argc, char *argv[])
{
/*Variables globales*/
int i, j; /*Indices du parcours des lignes et colonnes de la matrice*/
double MatSimple[TAILLE_L][TAILLE_C]; /*Matrice simple à traiter*/
double vect[TAILLE_C];
/*Remplissage de la matrice simple selon deux conditions*/
for (i=0; i<TAILLE_L; i++){
for (j=0; j<TAILLE_C; j++){
if (i%5 ==0)
MatSimple[i][j] = 2.00 ;
else
MatSimple[i][j] = 0. ;
}
}
printf("TEST 1 OK\n\n");
/*Affichage de la matrice simple*/
for (i=0; i<TAILLE_L; i++){
printf("\n_____________________________________________________________\n");
printf("Ligne %d :",(i+1));
for (j=0; j<TAILLE_C; j++){
printf("%lf | ", MatSimple[i][j]);
}
}
printf("\n\n") ;
printf("TEST 2 OK\n\n");
for(i=0 ; i<TAILLE_C ; i++){
vect[i] = MatSimple[2,i]; /*double <- double POURQUOI CA MARCHE PAS???*/
}/*Creux.c:125: error: incompatible types in assignment*/
printf("TEST 3 OK\n\n");
for(i=0 ; i<TAILLE_C ; i++){
printf("%lf ... ",vect[i]);
}
printf("\n");
printf("TEST 4 OK\n\n");
return 0;
} |
Voici le résultat de ma compilation (Je travaille sous MinGW Studio et je compile avec GCC, sous WinXP) :
--------------------Configuration: TESTFOR - Debug--------------------
Compiling source file(s)...
testFOR.c
testFOR.c: In function `main':
testFOR.c:33: warning: left-hand operand of comma expression has no effect
testFOR.c:33: error: incompatible types in assignment
testFOR.c:45:2: warning: no newline at end of file
TESTFOR.exe - 1 error(s), 2 warning(s)
Avez-vous une idée ?
Moi je comprends pas pourquoi je peux pas remplir mon vecteur vect par le contenu de ma matrice simple...est-ce à cause du fait que je les déclare en double ?
En effet, lorsque je modifie le code avec des int ou lieu de double :
Code:
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 40 41 42 43 44 45 46 47
| #include <stdio.h>
#include <stdlib.h>
#define TAILLE_L 30
#define TAILLE_C 10
int main(int argc, char *argv[])
{
/*Variables globales*/
int i, j; /*Indices du parcours des lignes et colonnes de la matrice*/
int MatSimple[TAILLE_L][TAILLE_C]; /*Matrice simple à traiter*/
int vect[TAILLE_C];
/*Remplissage de la matrice simple selon deux conditions*/
for (i=0; i<TAILLE_L; i++){
for (j=0; j<TAILLE_C; j++){
if (i%5 ==0)
MatSimple[i][j] = 2 ;
else
MatSimple[i][j] = 0 ;
}
}
printf("TEST 1 OK\n\n");
/*Affichage de la matrice simple*/
for (i=0; i<TAILLE_L; i++){
printf("\n_____________________________________________________________\n");
printf("Ligne %d :",(i+1));
for (j=0; j<TAILLE_C; j++){
printf("%d | ", MatSimple[i][j]);
}
}
printf("\n\n") ;
printf("TEST 2 OK\n\n");
for(i=0 ; i<TAILLE_C ; i++){
vect[i] = MatSimple[2,i]; /*double <- double POURQUOI CA MARCHE PAS???*/
}/*Creux.c:125: error: incompatible types in assignment*/
printf("TEST 3 OK\n\n");
for(i=0 ; i<TAILLE_C ; i++){
printf("%d ... ",vect[i]);
}
printf("\n");
printf("TEST 4 OK\n\n");
return 0;
} |
Citation:
TEST 1 OK
_____________________________________________________________
Ligne 1 :2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
_____________________________________________________________
Ligne 2 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 3 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 4 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 5 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 6 :2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
_____________________________________________________________
Ligne 7 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 8 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 9 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 10 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 11 :2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
_____________________________________________________________
Ligne 12 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 13 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 14 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 15 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 16 :2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
_____________________________________________________________
Ligne 17 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 18 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 19 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 20 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 21 :2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
_____________________________________________________________
Ligne 22 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 23 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 24 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 25 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 26 :2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
_____________________________________________________________
Ligne 27 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 28 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 29 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
_____________________________________________________________
Ligne 30 :0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
TEST 2 OK
TEST 3 OK
2292400 ... 2292440 ... 2292480 ... 2292520 ... 2292560 ... 2292600 ... 2292640
... 2292680 ... 2292720 ... 2292760 ...
TEST 4 OK
Terminated with return code 0
Press any key to continue ...
Les résultats renvoyés ressemblent plus à des adresses qu'aux int que j'ai mis dedans???