You are on page 1of 4

#ifndef GESTIONCLIENT_H_INCLUDED

#define GESTIONCLIENT_H_INCLUDED

typedef struct
{
int code;
char *nom;
char* prenom;
char* telephone;
}Client;

typedef struct ClientElement


{
Client *clt;
struct ClientElement *suivant;
}ClientElement;

Client * createClient ();


void displayClient(Client *);
ClientElement* createClientElement ();
ClientElement* trouverFinListeClients();
void addClientToList();
void diplayClientsList();
Client *getClient();
void deleteClient ();
void updateClient();

#endif // GESTIONCLIENT_H_INCLUDED

#include "gestionClient.h"

Client * createClient ()
{
Client *clt=(Client*)malloc(sizeof(Client));
char nom[20],prenom[20],telephone[20];

printf("\n\tEntrer le code client : ");


scanf("%d",&clt->code);

printf("\n\tEntrer le nom du client : ");


scanf("%s",nom);
clt->nom=(char*)malloc(sizeof(char)*strlen(nom));
strcpy(clt->nom,nom);

printf("\n\tEntrer le prenom du client : ");


scanf("%s",prenom);
clt->prenom=(char*)malloc(sizeof(char)*strlen(prenom));
strcpy(clt->prenom,prenom);

printf("\n\tEntrer le numero de telephone du client : ");


scanf("%s",telephone);
clt->telephone=(char*)malloc(sizeof(char)*strlen(telephone));
strcpy(clt->telephone,telephone);

return clt;
}
void displayClient(Client *clt)
{
printf("\t%d %s %s %s\n",clt->code,clt->nom,clt->prenom,clt->telephone);
}

ClientElement* createClientElement ()
{
ClientElement *cltElem=(ClientElement*)malloc(sizeof(ClientElement));
cltElem->suivant=NULL;
cltElem->clt=createClient();
return cltElem;
}

ClientElement* trouverFinListeClients()
{
ClientElement *cltElem;
for(cltElem=clientsList;cltElem->suivant!=NULL;cltElem=cltElem->suivant);
return cltElem;
}

void addClientToList()
{
ClientElement *cltElem=NULL;
cltElem=createClientElement();
if(clientsList==NULL)
{
clientsList=cltElem;
return;
}
else
{
ClientElement *ptr;
ptr=trouverFinListeClients(clientsList);
ptr->suivant=cltElem;
}
}

void diplayClientsList()
{
ClientElement *cltElem;
for(cltElem=clientsList;cltElem!=NULL;cltElem=cltElem->suivant)
{
displayClient(cltElem->clt);
}
}

Client *getClient()
{
int code;
printf("\n\t>Code du client : ");
scanf("%d",&code);
ClientElement *cltElem;
for(cltElem=clientsList;cltElem!=NULL;cltElem=cltElem->suivant)
{
if(cltElem->clt->code == code)
return cltElem->clt;
}
return NULL;
}

void deleteClient ()
{
int code;
printf("\n\t>Veillez entrer le code du client a supprimer : ");
scanf("%d",&code);
ClientElement *cltElem,*cltElemSup;
if(clientsList==NULL)
return;
if(clientsList->clt->code==code)
{
cltElem=clientsList;
clientsList=clientsList->suivant;
free(cltElem);
return;
}
for(cltElem=clientsList;cltElem!=NULL;cltElem=cltElem->suivant)
{
if(cltElem->suivant->clt->code == code)
{
cltElemSup=cltElem->suivant;
cltElem->suivant=cltElemSup->suivant;
free(cltElemSup);
return;
}
}
}

void updateClient()
{
int code;
char nom[20],prenom[20],telephone[20];
printf("\n\t>Veillez entrer le code du client a modifier : ");
scanf("%d",&code);
ClientElement *cltElem;
if(clientsList==NULL)
return;
for(cltElem=clientsList;cltElem!=NULL;cltElem=cltElem->suivant)
{
if(cltElem->clt->code == code)
{
printf("\n\tNom : ");
scanf("%s",nom);
cltElem->clt->nom=(char*)malloc(sizeof(char)*strlen(nom));
strcpy(cltElem->clt->nom,nom);

printf("\n\tPrenom : ");
scanf("%s",prenom);
cltElem->clt->prenom=(char*)malloc(sizeof(char)*strlen(prenom));
strcpy(cltElem->clt->prenom,prenom);

printf("\n\tNumero de telephone : ");


scanf("%s",telephone);
cltElem->clt->telephone=(char*)malloc(sizeof(char)*strlen(telephone));
strcpy(cltElem->clt->telephone,telephone);
return;
}
}
}

You might also like