Problème allocation structure
Bonjour,
Je crois que j'ai un probleme d'allocation car j'ai cette erreur : Violation d'accès lors de la lecture de l'emplacement ...
voila mes deux structures
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
typedef struct Employe
{
char date[10];
char nom[30];
int num;
}Employe;
typedef struct Entreprise
{
char nom[30];
struct Employe tabemp[30];
struct Entreprise *suivant;
}Entreprise; |
Fonction ajout entreprise
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
|
void ajouterEnTete( Entreprise ** pListe, char *n, Employe tab[30] )
{
Entreprise *ancienPremier ;
Entreprise *nouvelEntreprise ;
int i;
nouvelEntreprise = (Entreprise *)malloc( sizeof( Entreprise ) ) ;
if( nouvelEntreprise == NULL ) {
printf( "erreur d'allocation, arrêt du programme \n" ) ;
exit(-1) ;
}
strcpy(nouvelEntreprise->nom, n ) ;
for(i=0;i<3;i++){
nouvelEntreprise->tabemp[i].num = tab[i].num;
strcpy(nouvelEntreprise->tabemp[i].nom,tab[i].nom);
strcpy(nouvelEntreprise->tabemp[i].date,tab[i].date);
}
nouvelEntreprise->suivant = NULL ;
if( *pListe == NULL ){
nouvelEntreprise->suivant = NULL ;
}
else {
ancienPremier = *pListe ;
nouvelEntreprise->suivant = ancienPremier ;
}
*pListe = nouvelEntreprise;
} |
procedure saisir entreprise
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
void saisirEntreprise(char *n, Employe tab[30] )
{
int i,numemp;
char nomemp[30],dateemp[10];
printf( "saisir un nom : \n" );
scanf( "%s", n) ;
for(i=0;i<3;i++) {
printf("rentrez un nom,une date d'inscription(JJ/MM/AAAA) et un numero");
scanf("%s %s %d", nomemp,dateemp,&numemp);
strcpy(tab[i].nom,nomemp);
strcpy(tab[i].date,dateemp);
tab[i].num=numemp;
}
} |
procedure afficher
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
void afficherListe( Entreprise *liste )
//--------------------------------------
// affichage de tous les éléments de la liste
{
int i,num;
char nom[30],date[10];
if( liste == NULL ) {
printf( "affichage impossible, la liste est vide\n" ) ;
return ;
}
while(liste != NULL ){
printf( "nom = %s\n", liste->nom) ;
liste = liste->suivant ;// passage au maillon suivant
for(i=0;i<3;i++)
strcpy(nom,liste->tabemp[i].nom);
strcpy(date,liste->tabemp[i].date);
num=liste->tabemp[i].num;
printf( "num = %d \tnom = %s \tdate embauche = %s\n", num, nom, date) ;
}
} |
et mon main
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| void main()
{
Entreprise * maliste = NULL ;
int choix;
char n1[30];
Employe tab1[30];
saisirEntreprise(n1,tab1);
ajouterEnQueue(&maliste,n1,tab1);
afficherListe(maliste);
} |
Mon erreur est renvoyée lors de l'execution de la procedure afficherliste au moment où je veux afficher les noms, num et date des employés.
Pourriez vous m'aider svp?