ok ci dessous les fichiers du programme, ça compile correctement sous VS 2010.
Merci Beaucoup :)
Fichier main.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "LSTCON.H"
#include "LISTCONPRIM.H"
void afficherMenuPrincipal(LISTE_CONT listContacts);
void afficherMenuContact(LISTE_CONT listContacts);
void ajouterUnContact();
void supprimerUnContact(LISTE_CONT listContacts);
extern int insererlisteCont(LISTE_CONT,ELEMENT_CONT,int);
extern LISTE_CONT listeContCreer ( void);
extern int supprimerlisteCont(LISTE_CONT l,int pos);
extern void listeContAfficher (LISTE_CONT l);
void main()
{
//Création des listes qu'on va utiliser dans tout le programme.
LISTE_CONT listeDesContat = listeContCreer();
//Pour_CODE_SOURCE l'allocation de mémoire fonctionne correctement si on fait un appel ici
listeContEstSaturee (listeDesContat);
afficherMenuPrincipal(listeDesContat);
}
void afficherMenuContact(LISTE_CONT listContacts)
{
char choix;
do
{
system("cls");
printf("\t\t **************************************** \n");
printf("\t\t **************************************** \n");
printf("\t\t ********** Gestion de Contact ********** \n");
printf("\t\t **************************************** \n");
printf("\t\t **************************************** \n\n");
printf("\t\t\t Veuillez faire un choix : \n\n");
printf("\t\t\t 1- Ajouter un Contact : \n");
printf("\t\t\t 2- Afficher les Contacts : \n");
printf("\t\t\t 3- Supprimer un contact : \n");
printf("\t\t\t 4- Afficher le plus contacté : \n");
printf("\t\t\t 5- Afficher le jamais contacté : \n");
printf("\t\t\t 6- Retour : \n");
scanf("%c",&choix);
}
while(
(choix != '1')
&& (choix != '2')
&& (choix != '3')
&& (choix != '4')
&& (choix != '5')
&& (choix != '6'));
switch(choix)
{
case '1':
ajouterUnContact(listContacts);
printf("Operation d'ajout terminée ! Appuyez sur une touche,\n");
getchar();
afficherMenuContact(listContacts);
break;
case '2':
listeContAfficher(listContacts);
printf("Operation d'affichage terminée ! Appuyez sur une touche,\n");
getchar();
afficherMenuContact(listContacts);
break;
case '3':
supprimerUnContact(listContacts);
printf("Operation de suppression terminée ! Appuyez sur une touche,\n");
getchar();
afficherMenuContact(listContacts);
break;
case '4':
//Afficher le plus contacté
break;
case '5':
//Afficher le jamais contacté
break;
case '6':
afficherMenuPrincipal(listContacts);
break;
default:
break;
}
}
void afficherMenuPrincipal(LISTE_CONT listContacts)
{
char choix;
do
{
system("cls");
printf("********************************************************************* \n");
printf("********************************************************************* \n");
printf("********** Application de Gestion de Message et de Contact ********** \n");
printf("********** Bienvenue ********** \n");
printf("********************************************************************* \n");
printf("********************************************************************* \n\n");
printf("\t\t\t Veuillez faire un choix : \n\n");
printf("\t\t\t 1- Gestion de Contact : \n");
printf("\t\t\t 2- Gestion de Messages : \n");
scanf("%c",&choix);
}while((choix!='1')&&(choix!='2'));
switch(choix)
{
case '1':
afficherMenuContact(listContacts);
break;
case '2':
break;
default:
break;
}
}
void ajouterUnContact(LISTE_CONT listContacts)
{
ELEMENT_CONT contact = elementConcreer();
printf("Donnez le nom du contact \n");
scanf("%50s",contact->nom);
printf("Donnez le numéro du contact \n");
scanf("%8s",contact->numero);
printf("Donnez l'email du contact \n");
scanf("%30s",contact->email);
//Pour_CODE_SOURCE l'allocation de mémoire ne fonctionne pas si on fait une allocation de mémoire sous cette fonction
insererlisteCont(listContacts,contact,listContacts->lg+1);
}
void supprimerUnContact(LISTE_CONT listContacts)
{
int contactIndex;
printf("Donnez l'index du contact \n");
scanf("%s",&contactIndex);
supprimerlisteCont(listContacts,contactIndex);
}
ELTCON.C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ELTCONPRIM.H"
ELEMENT_CONT elementConcreer()
{
ELEMENT_CONT e;
e = (ELEMENT_CONT)malloc(sizeof(ELEMENT_CONT));
memset(e->email,0,sizeof(e->email));
memset(e->nom,0,sizeof(e->nom));
memset(e->numero,0,sizeof(e->numero));
return e;
}
void elementCondetruire(ELEMENT_CONT e)
{
free(e);
}
void elementConafficher(ELEMENT_CONT e)
{
printf("nom contact : %s \n",e->nom);
printf("numero contact : %s \n",e->numero);
printf("email contact : %s \n",e->email);
}
void elementConcopier(ELEMENT_CONT* e1,ELEMENT_CONT e2)
{
}
void elementConaffecter(ELEMENT_CONT* e1,ELEMENT_CONT e2)
{
}
int elementConcomparer(ELEMENT_CONT e1,ELEMENT_CONT e2)
{
}
LSTCON.C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ELTCON.H"
#include "LSTCON.H"
#include "LISTCONPRIM.H"
NOEUD_CONT noeudConCreer(ELEMENT_CONT e)
{
NOEUD_CONT n;
n =(NOEUD_CONT)malloc(sizeof(structNoeudCONT));//Ceci devrait marcher
if(!n)
printf ("\nPlus d'espace");
else
{
elementConaffecter(&n->info, e);
n->suivant = NULL;
}
return n;
}
void noeudConDetruire(NOEUD_CONT n)
{
elementCondetruire(n->info);
free(n);
}
LISTE_CONT listeContCreer ( void)
{
LISTE_CONT l;
l=(LISTE_CONT)malloc(sizeof(laStructCONT));
if(!l)
printf("\nProblème de mémoire");
else
{
l->lg = 0;
l->tete = NULL; /* initialiser la tête */
}
return(l);
}
void listeContDetruire ( LISTE_CONT l)
{
int i;
NOEUD_CONT p, q;
q= l->tete;
for(i = 1;i <= l->lg; i++)
{
p=q;
q=q->suivant;
noeudConDetruire(p);
}
free(l);
}
void listeContAfficher (LISTE_CONT l)
{
int i=1;
NOEUD_CONT p;
p= l->tete;
for(i = 1;i <= l->lg; i++)
{
printf("=== Détails du contact num %d ===\n",i);
elementConafficher(p->info);
p= p->suivant;
}
}
int listeContEstSaturee ( LISTE_CONT l)
{
int saturee = 1; /* on suppose mémoire saturée */
NOEUD_CONT temp= (NOEUD_CONT)malloc ( sizeof(structNoeudCONT)); //Pour_CODE_SOURCE Ceci devrait marcher dans tous les cas
if(temp != NULL)
{
saturee = 0; /* mémoire non saturée */
free(temp);
}
return saturee;
}
int listeContEstVide(LISTE_CONT l)
{
return (l->lg == 0);
}
int insererlisteCont(LISTE_CONT l ,ELEMENT_CONT e,int pos)
{
int succee=1;
int i;
NOEUD_CONT n, p, q; // c des pointeurs sur noeud c equivalent à: // structNoeud * n
if (listeContEstSaturee(l))
{
printf ("\nListe saturée");
succee=0;
}
else
{
if ((pos < 1) || (pos > l->lg + 1))
{
printf ("\nPosition invalide");
succee=0;
}
else
{
n=noeudConCreer(e); /*on est sûr que la réservation va se faire car la mémoire n'est pas saturée*/
if (pos == 1) /*insertion en tête de liste*/
{
n->suivant=l->tete;
l->tete = n;
}
else /*cas général (pos > 1) */
{
q= l->tete;
for (i=1; i<pos; i++)
{
p = q;
q = q->suivant;
}
// q désigne l'élément de rang pos et p son prédécesseur
p->suivant=n;
n->suivant=q;
}
(l->lg)++;
}
}
return succee;
}
int supprimerlisteCont(LISTE_CONT l,int pos)
{
int i;
int succee=1;
NOEUD_CONT p, q;
if (listeContEstVide(l))
{
printf ("\nListe vide");
succee=0;
}
else
{
if ((pos < 1) || (pos > l->lg))
{
printf ("\nPosition invalide");
succee=0;
}
else
{
q = l->tete;
/*suppression en tête de liste*/
if (pos == 1)
l->tete=l->tete->suivant;
else
{ /*cas général (pos > 1) */
for (i=1; i<pos; i++)
{
p = q;
q = q->suivant;
}
p->suivant=q->suivant;
}
// q désigne l'élément de rang pos et p son prédécesseur
noeudConDetruire(q);
(l->lg)--;
}
}
return succee;
}
ELEMENT_CONT recupererlisteCont(LISTE_CONT l ,int pos)
{
/* s'il ya une erreur on affiche un message et on retourne un element vide */
ELEMENT_CONT elt= elementConcreer();
int i;
NOEUD_CONT p;
if (listeContEstVide(l))
printf ("\nListe vide");
else
{
if ((pos < 1) || (pos > l->lg))
printf ("\nPosition invalide");
else
{
p= l->tete;
for (i=1; i<pos; i++)
p = p->suivant;
elementConaffecter(&elt,p->info);
}
}
return(elt);
}
LISTE_CONT listeContCopier(LISTE_CONT l)
{
LISTE_CONT LR = listeContCreer();
int i;
ELEMENT_CONT elt;
for(i = 1;i <= l->lg; i++)
{
elt=elementConcreer();
elementConcopier(&elt, recupererlisteCont(l,i));
insererlisteCont(LR,elt, i);
}
return LR;
}
int listeContcomparer(LISTE_CONT l1 ,LISTE_CONT l2)
{
int test= 1;
int i=1;
if (listeContTaille(l1) != listeContTaille(l2))
test= 0;
while ((i<=listeContTaille(l1)) && (test))
{
if (!elementConcomparer(recupererlisteCont(l1,i),recupererlisteCont(l2,i)))
test=0;
i++;
}
return test;
}
int listeContTaille(LISTE_CONT l)
{
return (l->lg);
}
ELTCON.H
#ifndef _ELTCON_H
#define _ELTCON_H
typedef struct
{
char nom[50];
char numero[9];
char email[30];
}CONTACT,*ELEMENT_CONT;
#endif
ELTCONPRIM.H
#ifndef _ELTCONPRIM_H
#define _ELTCONPRIM_H
#include "ELTCON.H"
ELEMENT_CONT elementConcreer();
void elementCondetruire(ELEMENT_CONT);
void elementConafficher(ELEMENT_CONT);
void elementConcopier(ELEMENT_CONT*,ELEMENT_CONT);
void elementConaffecter(ELEMENT_CONT*,ELEMENT_CONT);
int elementConcomparer(ELEMENT_CONT,ELEMENT_CONT);
#endif
LSTCON.H
#ifndef _LSTCON_H
#define _LSTCON_H
#include "ELTCONPRIM.H"
typedef struct structNoeudCONT
{
ELEMENT_CONT info;
struct structNoeudCONT * suivant;
}structNoeudCONT, * NOEUD_CONT;
typedef struct
{
NOEUD_CONT tete;
int lg;
}laStructCONT,*LISTE_CONT;
#endif
LISTCONPRIM.H
#ifndef _LSTSMSPRIM_H
#define _LSTSMSPRIM_H
#include "LSTCON.H"
NOEUD_CONT noeudCreer(ELEMENT_CONT e);
LISTE_CONT listeContCreer ( void);
void listeContDetruire ( LISTE_CONT);
void listeContAfficher (LISTE_CONT);
int listeContEstSaturee ( LISTE_CONT);
int listeContEstVide(LISTE_CONT);
int insererlisteCont(LISTE_CONT,ELEMENT_CONT,int);
int supprimerlisteCont(LISTE_CONT,int);
ELEMENT_CONT recupererlisteCont(LISTE_CONT,int);
LISTE_CONT listeContCopier(LISTE_CONT);
int listeContcomparer(LISTE_CONT,LISTE_CONT);
int listeContTaille(LISTE_CONT);
#endif
--