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 :

passage parametre int** [2]


Sujet :

C

  1. #1
    Membre averti
    Inscrit en
    Octobre 2010
    Messages
    22
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 22
    Par défaut passage parametre int** [2]
    Bonjour bonjour,

    Voila jai un tableau nommé matricegroupegeneralisant de type [2][][].
    Je souhaiterais le passer en paramètre pour faire une allocation dynamique.

    fonction qui pose probleme : allocmatrices
    utilisation ligne 78
    declaration ligne 161

    lerreur de compilation :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    test.c: In function ‘generalisationAttribut’:
    test.c:78:2: warning: passing argument 3 of ‘allocmatrices’ from incompatible pointer type [enabled by default]
    test.c:12:6: note: expected ‘int ***’ but argument is of type ‘int ** (*)[2]’
    a: 0 b: 1
    type de gen : 1
    fichier de generalisation utilisee : genO.txt
     nbgroupegeneralisant :3
    5 5 5 5 5 
    5 5 5 5 5 
    5 5 5 5 5 
    5 5 5 5 5 
    Error: the input file was not found!
    Error: the input file was not found!
    larimsna1@larimsna1:~/Desktop/corontest17/gen$
    Voici mon programme :
    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
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #define Nmcl 200 //nombre maxi de caractere pour ligne attribut ou objet 
    #define Nmcm 20  //nombre maxi de caractere pour un mot
    #define nbligneenteteGpar1 4
    #define nbligneenteteGenU 2
     
    void ouvrir_fic(FILE**, char*, char*);
    int determinationtypedegenchoisi(FILE* fichG);
    int** generalisationAttribut(char* nomfichierdegen, int nbligneMat,int nbcolonneMat);
    void allocmatrices(int*** Matrice,int** nbelementpargroupe, int** matricegroupegeneralisant [2],int nbgroupegeneralisant, int nbligneMat, int nbcolonneMat);
    void allocationdynamiquetableauunedimdentier(int** nbelementpargroupe, int nbgroupegeneralisant);
    void allocationdynamiquetableaudeuxdimdentier(int*** Matrice, int nbligne, int nbcolonne);
    void affichageMatrice(int departligne, int nbligne, int departcolonne, int nbcolonne, int** Matrice);
    int comptagenbgroupegeneralisant(FILE* fichTmp);
     
     
    void main(int args, char **argv)
    {
    	FILE * fichG=NULL; // fichier de presentation des generalisations
    	int** Matrice; // le contexte
     
    	int typedegen; //generalisation sur objet, sur attribut ou sur objet et attribut
    	char NomUniqueFichierGen[Nmcm];
    	char NomFichierGenA[Nmcm];
    	char NomFichierGenO[Nmcm];
    	int i;
    	char chaine[Nmcl];
     
    	ouvrir_fic(&fichG, argv[2],"r");
    	typedegen=determinationtypedegenchoisi(fichG);
    	printf("type de gen : %d\n",typedegen);
     
    	for(i=0;i<nbligneenteteGpar1;i++)       // on saute les lignes de commentaires
    	{
    		fgets(chaine, sizeof chaine, fichG);
    	}
     
    	if(typedegen==0 || typedegen==1) // si qu'un seul fichier de generalisation
    	{
    		fscanf(fichG,"%s",NomUniqueFichierGen);
    		printf("fichier de generalisation utilisee : %s\n ",NomUniqueFichierGen);
    	}
     
     
    	Matrice=generalisationAttribut(NomUniqueFichierGen,4,5);
     
     
     
    	affichageMatrice(0,4,0,5, Matrice);
    }
     
     
     
     
     
    int** generalisationAttribut(char* nomfichierdegen, int nbligneMat,int nbcolonneMat)
    {
    	int* nbelementpargroupe; // nombre delement par groupe
    	int** Matrice; // le contexte
    	int** MatriceTransposee; // contexte transpose
    	int** Matricegenere;  // contexte de base+contexte genere
    	int** matricegroupegeneralisant [2]; // matrice de generalisation
    	int** groupegeneralisant [2]; // matrice de generalisation reduite
    	int i,j;
    	FILE * fichU=NULL;
    	FILE * fichTmp=NULL;
    	int nbgroupegeneralisant;
     
    	ouvrir_fic(&fichTmp, nomfichierdegen,"r");
    	nbgroupegeneralisant=comptagenbgroupegeneralisant(fichTmp);
    	printf("nbgroupegeneralisant :%d\n",nbgroupegeneralisant);
    	fclose(fichTmp);	
     
    	/// allocation dynamique des matrices
    	//allocmatrices();
    	allocmatrices(&Matrice,&nbelementpargroupe,&matricegroupegeneralisant,nbgroupegeneralisant,nbligneMat,nbcolonneMat);
     
    	allocationdynamiquetableaudeuxdimdentier(&Matricegenere,nbligneMat,nbcolonneMat+nbgroupegeneralisant);
     
    	/*allocationdynamiquetableaudeuxdimdentier(&matricegroupegeneralisant[0],nbgroupegeneralisant,nbligneMat);
    	allocationdynamiquetableaudeuxdimdentier(&matricegroupegeneralisant[1],nbgroupegeneralisant,nbcolonneMat);*/
     
    	allocationdynamiquetableaudeuxdimdentier(&groupegeneralisant [0],nbligneMat,nbcolonneMat);
    	allocationdynamiquetableaudeuxdimdentier(&groupegeneralisant [1],nbligneMat,nbcolonneMat);
    	for(i=0; i<nbligneMat;i++)
    	{
    		for(j=0; j<nbcolonneMat;j++)
    		{
    			Matrice[i][j]=5;
    		}
    	}
     
    	return(Matrice);
    }
     
    void ouvrir_fic(FILE** f, char* nom,char* type)
    { 
    *f=fopen(nom,type); 
    }	
     
    int determinationtypedegenchoisi(FILE* fichG)
    {
    	int c,a,b,typedegen;
    	c = fgetc(fichG);       // premiere parenthese
    	fscanf(fichG, "%d",&a); // premier chiffre
    	c = fgetc(fichG);	// virgule
    	fscanf(fichG, "%d",&b);	// second chiffre
    	c = fgetc(fichG);	// seconde parenthese
    	c = fgetc(fichG); 	// marqueur fin de ligne
    	printf("a: %d b: %d\n",a,b);
     
    	if(a==1)
    	{
    		if(b==0)
    		{
    			typedegen=0;
    		}
    		else
    		{
    			typedegen=2;
    		}
    	}
    	else
    	{
    		if(a==0 && b==1)
    		{
    			typedegen=1;
    		}
    		else
    		{
    			printf("pas de generalisation demandee\n");
    			exit(2);
    		}
    	}
    	return(typedegen);
    }
     
    int comptagenbgroupegeneralisant(FILE* f)
    {
    	int nb_ligne=0,c;
    	if (f == NULL)
    	{
    		printf("erreur lecture fichier pour comptagenbgroupegeneralisant\n");
    	}
    	else
    	{
    		while((c = fgetc(f)) != EOF)          //compteur de ligne
    		{
    			if(c == '\n')
    			{
    				nb_ligne++;
    			}
    		}
    		return(nb_ligne-nbligneenteteGenU); 
    	}
    }
     
     
    void allocmatrices(int*** Matrice,int** nbelementpargroupe, int** matricegroupegeneralisant [2],int nbgroupegeneralisant, int nbligneMat, int nbcolonneMat)
    {
    	//allocationdynamiquetableauunedimdentier(nbelementpargroupe, nbgroupegeneralisant);
    	allocationdynamiquetableaudeuxdimdentier(Matrice,nbligneMat,nbcolonneMat);
    }	
     
    void allocationdynamiquetableauunedimdentier(int** nbelementpargroupe, int nbgroupegeneralisant)
    {
    	*nbelementpargroupe=(int*) malloc (sizeof(int)*nbgroupegeneralisant); 
    }
     
     
    void allocationdynamiquetableaudeuxdimdentier(int*** Matrice, int nbligne, int nbcolonne)
    {
    	int i,j;
    	*Matrice=(int**) malloc (sizeof(int*)*nbligne);  // allocation dynamique de la matrice Matrice
    	for (i=0; i<nbligne; i++)
    	{
    		(*(Matrice))[i]=(int*) malloc (sizeof(int)*nbcolonne);
    	} 
    }
     
    void affichageMatrice(int departligne, int nbligne, int departcolonne, int nbcolonne, int** Matrice)
    {
    	int i,j;
    	for(i=departligne; i<nbligne;i++)
    	{
    		for(j=departcolonne; j<nbcolonne;j++)
    		{
    			printf("%d ",Matrice[i][j]);
    		}
    		printf("\n");
    	}
    }
    Merci beaucoup !!!

  2. #2
    Membre éprouvé
    Profil pro
    Inscrit en
    Février 2005
    Messages
    119
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 119
    Par défaut
    Salut,
    matricegroupegeneralisant
    allocationdynamiquetableaudeuxdimdentier


    Ce n'est pas très lisible je trouve. En géneral, on met des "_" pour séparer les mots ou des majuscules au débuts des mots (matrice_groupe_generalisant ou matriceGroupeGeneralisant). Essaye de trouver des noms plus courts aussi...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    void allocmatrices(int*** Matrice,int** nbelementpargroupe, int** matricegroupegeneralisant [2],int nbgroupegeneralisant, int nbligneMat, int nbcolonneMat);
    
    int** matricegroupegeneralisant [2]; // matrice de generalisation
    allocmatrices(&Matrice,&nbelementpargroupe,&matricegroupegeneralisant,nbgroupegeneralisant,nbligneMat,nbcolonneMat);
    /*&matricegroupegeneralisant est un int***[2] alors que allocmatrices attend un  int**[2] 
    (peut-être matricegroupegeneralisant, mais j'en sais rien, j'ai pas lu le code) */

  3. #3
    Membre chevronné

    Profil pro
    Inscrit en
    Août 2007
    Messages
    179
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 179
    Par défaut
    j'ai lu un peu en diagonale mais vu le peu de succès de ce post je me permets une petite remarque :

    Le troisième paramètre de allocmatrices est un int** [2] et matricegroupegeneralisant est un int** [2], du coup pourquoi ne pas passer directement matricegroupegeneralisant plutôt que son adresse?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    allocmatrices(&Matrice,&nbelementpargroupe,matricegroupegeneralisant,nbgroupegeneralisant,nbligneMat,nbcolonneMat);
    Bon, encore une fois j'ai lu vite et je fais peut être un peu la mouche du coche et ça ne fera peut être pas du tout ce que tu veux mais au moins ça devrait compiler.

  4. #4
    Membre émérite
    Avatar de Kirilenko
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2011
    Messages
    234
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 234
    Par défaut
    Salut,

    Étant donné la longueur de tes identificateurs et le nombre de variables, ton code est difficilement lisible. Toutefois, au vu de l'énoncé du problème, il semblerait que tu souhaiterais passer un pointeur vers un int **[2], auquel cas il te suffit de prendre un paramètre de type int **(*)[2]. Tu pourras ainsi modifier directement ta variable dans la fonction.

    Bonne fin de journée.
    Récursivité en C : épidémie ou hérésie ?

    "Pour être un saint dans l'Église de l'Emacs, il faut vivre une vie pure. Il faut se passer de tout logiciel propriétaire. Heureusement, être célibataire n'est pas obligé. C'est donc bien mieux que les autres églises" - Richard Stallman

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

Discussions similaires

  1. [XSLT] [JAXP] passage parametres lors de chainage xslt
    Par Pi2 dans le forum Format d'échange (XML, JSON...)
    Réponses: 1
    Dernier message: 22/02/2006, 09h38
  2. [servlet] passage parametre entier
    Par cmoa59 dans le forum Servlets/JSP
    Réponses: 2
    Dernier message: 03/03/2005, 10h03
  3. Fichier bat + FTP + passage parametres
    Par Leti dans le forum Scripts/Batch
    Réponses: 20
    Dernier message: 13/12/2004, 18h21
  4. [Reflection][Method] Passage de int en parametre
    Par seb_fou dans le forum API standards et tierces
    Réponses: 8
    Dernier message: 28/07/2004, 17h47
  5. [Reflection] Récupérer un constructeur ayant un paramètre int
    Par narmataru dans le forum API standards et tierces
    Réponses: 2
    Dernier message: 09/07/2004, 09h53

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