IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

error: incompatible types in assignment


Sujet :

C

  1. #1
    Membre éclairé
    Avatar de panda31
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Juin 2003
    Messages
    670
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : Conseil

    Informations forums :
    Inscription : Juin 2003
    Messages : 670
    Points : 848
    Points
    848
    Par défaut error: incompatible types in assignment
    Bonjour à tous,

    j'ai cette erreur que je ne parviens à comprendre compte tenu de mon code :

    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
    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 : 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
    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;
     
    }
    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???
    Michaël Mary
    Consultant PLM dans une société de conseil toulousaine
    Auditeur CNAM-IPST depuis septembre 2008
    "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
    John F. Woods
    mon cv et mon domaine et mon blog
    Aucune question technique par MP, svp

  2. #2
    Membre expérimenté
    Inscrit en
    Décembre 2004
    Messages
    1 478
    Détails du profil
    Informations forums :
    Inscription : Décembre 2004
    Messages : 1 478
    Points : 1 664
    Points
    1 664
    Par défaut
    Pour acceder aux elements d'un tableau multi-dimensionnel, on fait tableau[i][j], pas tableau[i,j]...

  3. #3
    Membre éclairé
    Avatar de panda31
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Juin 2003
    Messages
    670
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : Conseil

    Informations forums :
    Inscription : Juin 2003
    Messages : 670
    Points : 848
    Points
    848
    Par défaut
    Merci... J'ai honte de confondre les langages... Merci quand même... Bon ben résolu of course !
    Michaël Mary
    Consultant PLM dans une société de conseil toulousaine
    Auditeur CNAM-IPST depuis septembre 2008
    "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
    John F. Woods
    mon cv et mon domaine et mon blog
    Aucune question technique par MP, svp

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. error: incompatible types when assigning
    Par quentinb56 dans le forum C
    Réponses: 2
    Dernier message: 05/12/2013, 20h31
  2. error: incompatible types in assignment
    Par Ganondorf dans le forum Débuter
    Réponses: 6
    Dernier message: 16/09/2010, 16h04
  3. error: incompatible types in assignement
    Par Melwen dans le forum Débuter
    Réponses: 3
    Dernier message: 02/05/2010, 20h34
  4. Réponses: 4
    Dernier message: 25/02/2010, 17h14
  5. Réponses: 4
    Dernier message: 05/12/2005, 19h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo