Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "main.h"
- #include "structures.h"
- void afficher(structures *liste, char nom, char prenom , char classe, float *note)
- {
- structures *aff;
- aff = liste;
- if(strcmp(nom,"eleves")==NULL)
- {
- while(aff!=NULL)
- {
- printf("%s ",aff->nom);
- printf("%s ",aff->prenom);
- printf("%s ",aff->classe);
- printf("%f\n",aff->note);
- aff=aff->nxt;
- }
- }
- else if (strcmp(nom,liste->nom)==NULL)
- {
- while(aff != NULL)
- {
- //if (strcmp(nom,afficher->nom)==0)
- printf("%s ", aff->nom);
- printf("%s ", aff->prenom);
- printf("%s ", aff->classe);
- printf("%f \n\n", aff->note);
- aff = aff->nxt;
- }
- }
- }
- #include "main.h"
- #include "structures.h"
- static void purger(void)
- {
- int c;
- while ((c = getchar()) != '\n' && c != EOF)
- {}
- }
- static void clean (char *commande)
- {
- char *p = strchr(commande, '\n');
- if (p)
- {
- *p = 0;
- }
- else
- {
- purger();
- }
- }
- void main()
- {
- printf("Voici les differentes commandes possibles :\n\n");
- printf("- ajouter nom prenom classe note\n");
- printf("- supprimer nom prenom classe note\n");
- printf("- modifier nom prenom classe note\n\n");
- char commande[TAILLE];
- char *tab1,*tab2,*tab3,*tab4,*tab5,*tab6,*tab7,*tab8;
- char *nom,*prenom,*classe;
- float note;
- structures *liste=NULL;
- while(1)
- {
- do
- {
- tab1 = NULL;
- tab2 = NULL;
- tab3 = NULL;
- tab4 = NULL;
- tab5 = NULL;
- tab6 = NULL;
- tab7 = NULL;
- tab8 = NULL;
- tab1=strtok(commande," ");
- tab2=strtok(NULL," ");
- tab3=strtok(NULL," ");
- tab4=strtok(NULL," ");
- tab5=strtok(NULL," ");
- tab6=strtok(NULL," ");
- tab7=strtok(NULL," ");
- tab8=strtok(NULL," ");
- if (tab8!=NULL)
- printf("Veuillez entrer une nouvelle commande");
- }while (tab8!=NULL);
- gets(commande);
- decoupage(commande);
- }
- }
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #define TAILLE 100
- #include "main.h"
- #include "structures.h"
- typedef structures* liste;
- int sup(int argc, char **argv)
- {
- /* Déclarons 3 listes chaînées de façons différentes mais
- équivalentes */
- liste liste1 = NULL;
- structures *liste2 = NULL;
- struct structures *liste3 = NULL;
- return 0;
- }
- #include "main.h"
- typedef struct structures
- {
- char nom[TAILLE];
- char prenom[TAILLE];
- char classe[TAILLE];
- float note;
- struct structures *nxt;
- }structures;
- #include "main.h"
- #include "structures.h"
- structures* ajouter(structures *liste,char *nom,char *prenom,char *classe,float *note, int *compteur)
- {
- if(liste==NULL)
- {
- compteur=compteur++;
- structures* element = malloc(sizeof(structures));
- /* On crée un nouvel élément */
- element->nxt=NULL;
- /* On assigne la valeur au nouvel élément */
- strcpy(element->nom,nom);
- strcpy(element->prenom,prenom);
- strcpy(element->classe,classe);
- element->note=*note;
- /* On assigne l'adresse de l'élément suivant au nouvel élément
- */
- element->nxt = liste;
- liste=element;
- /* On retourne la nouvelle liste, i.e. le pointeur sur le
- premier élément */
- return element;
- }
- }
- #include "main.h"
- #include "structures.h"
- structures* modifier(structures *liste,char *nom,char *prenom,char *classe,float *note)
- {
- structures *structures2=liste;
- while(liste!=NULL)
- {
- rechercher(nom,prenom);
- strcpy(structures2->classe,classe);
- structures2->note;
- }
- }
- #include "main.h"
- #include "structures.h"
- void decoupage(commande)
- {
- char *i;
- i = strtok(commande," ");
- char *nom;
- char *liste;
- char *prenom;
- char *classe;
- float *note;
- int compteur;
- nom=strtok(NULL," ");
- prenom=strtok(NULL," ");
- classe=strtok(NULL," ");
- note=strtok(NULL," ");
- if (strcmp(i,"ajouter")==NULL)
- {
- ajouter(liste,nom,prenom,classe,note) ;
- printf("Vous avez ajoute un eleve.\n\n");
- }
- // On utilise la fonction ajouter.
- else if (strcmp(i,"supprimer")==NULL)
- {
- sup(liste,nom,prenom,classe,note);
- printf("Vous avez supprime un eleve.\n\n") ;
- }
- // On utilise la fonction supprimer.
- else if (strcmp(i,"modifier")==NULL)
- {
- modifier(liste,nom,prenom,classe,note);
- printf("Vous avez remplace un eleve\n\n");
- }
- // On utilise la fonction modifier.
- else if (strcmp(i,"afficher")==NULL)
- {
- afficher(liste,nom,prenom,classe,note);
- }
- // On definit la fonction afficher.
- }
- #include "main.h"
- #include "structures.h"
- structures* rechercher(structures *liste, char *nom, char *prenom)
- {
- structures *recher=liste;
- /* Tant que l'on n'est pas au bout de la liste */
- while(recher != NULL)
- {
- if(recher->nom==nom && recher->prenom==prenom)
- {
- /* Si l'élément a la valeur recherchée, on renvoie son
- adresse */
- return recher;
- }
- recher=recher->nxt;
- }
- return NULL;
- }
- // Cette fonction permet de retrouver le nom et le prenom pour la fonction modifier.
Add Comment
Please, Sign In to add comment