Guest User

Untitled

a guest
Apr 19th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. #include "main.h"
  2. #include "structures.h"
  3.  
  4. void afficher(structures *liste, char nom, char prenom , char classe, float *note)
  5. {
  6. structures *aff;
  7. aff = liste;
  8.  
  9. if(strcmp(nom,"eleves")==NULL)
  10. {
  11. while(aff!=NULL)
  12. {
  13. printf("%s ",aff->nom);
  14. printf("%s ",aff->prenom);
  15. printf("%s ",aff->classe);
  16. printf("%f\n",aff->note);
  17. aff=aff->nxt;
  18. }
  19. }
  20.  
  21. else if (strcmp(nom,liste->nom)==NULL)
  22. {
  23. while(aff != NULL)
  24. {
  25. //if (strcmp(nom,afficher->nom)==0)
  26. printf("%s ", aff->nom);
  27. printf("%s ", aff->prenom);
  28. printf("%s ", aff->classe);
  29. printf("%f \n\n", aff->note);
  30.  
  31. aff = aff->nxt;
  32. }
  33. }
  34. }
  35.  
  36.  
  37.  
  38. #include "main.h"
  39. #include "structures.h"
  40.  
  41. static void purger(void)
  42. {
  43. int c;
  44.  
  45. while ((c = getchar()) != '\n' && c != EOF)
  46. {}
  47. }
  48.  
  49. static void clean (char *commande)
  50. {
  51. char *p = strchr(commande, '\n');
  52.  
  53. if (p)
  54. {
  55. *p = 0;
  56. }
  57.  
  58. else
  59. {
  60. purger();
  61. }
  62. }
  63.  
  64. void main()
  65. {
  66. printf("Voici les differentes commandes possibles :\n\n");
  67. printf("- ajouter nom prenom classe note\n");
  68. printf("- supprimer nom prenom classe note\n");
  69. printf("- modifier nom prenom classe note\n\n");
  70.  
  71. char commande[TAILLE];
  72. char *tab1,*tab2,*tab3,*tab4,*tab5,*tab6,*tab7,*tab8;
  73. char *nom,*prenom,*classe;
  74. float note;
  75. structures *liste=NULL;
  76.  
  77. while(1)
  78. {
  79. do
  80. {
  81. tab1 = NULL;
  82. tab2 = NULL;
  83. tab3 = NULL;
  84. tab4 = NULL;
  85. tab5 = NULL;
  86. tab6 = NULL;
  87. tab7 = NULL;
  88. tab8 = NULL;
  89.  
  90. tab1=strtok(commande," ");
  91. tab2=strtok(NULL," ");
  92. tab3=strtok(NULL," ");
  93. tab4=strtok(NULL," ");
  94. tab5=strtok(NULL," ");
  95. tab6=strtok(NULL," ");
  96. tab7=strtok(NULL," ");
  97. tab8=strtok(NULL," ");
  98. if (tab8!=NULL)
  99.  
  100. printf("Veuillez entrer une nouvelle commande");
  101. }while (tab8!=NULL);
  102.  
  103. gets(commande);
  104. decoupage(commande);
  105. }
  106. }
  107.  
  108.  
  109.  
  110. #include <stdlib.h>
  111. #include <stdio.h>
  112. #include <string.h>
  113. #define TAILLE 100
  114.  
  115.  
  116.  
  117. #include "main.h"
  118. #include "structures.h"
  119.  
  120. typedef structures* liste;
  121. int sup(int argc, char **argv)
  122. {
  123. /* Déclarons 3 listes chaînées de façons différentes mais
  124. équivalentes */
  125. liste liste1 = NULL;
  126. structures *liste2 = NULL;
  127. struct structures *liste3 = NULL;
  128. return 0;
  129. }
  130.  
  131.  
  132.  
  133.  
  134. #include "main.h"
  135.  
  136. typedef struct structures
  137. {
  138. char nom[TAILLE];
  139. char prenom[TAILLE];
  140. char classe[TAILLE];
  141. float note;
  142. struct structures *nxt;
  143. }structures;
  144.  
  145.  
  146.  
  147.  
  148. #include "main.h"
  149. #include "structures.h"
  150.  
  151. structures* ajouter(structures *liste,char *nom,char *prenom,char *classe,float *note, int *compteur)
  152. {
  153. if(liste==NULL)
  154. {
  155. compteur=compteur++;
  156. structures* element = malloc(sizeof(structures));
  157. /* On crée un nouvel élément */
  158. element->nxt=NULL;
  159. /* On assigne la valeur au nouvel élément */
  160. strcpy(element->nom,nom);
  161. strcpy(element->prenom,prenom);
  162. strcpy(element->classe,classe);
  163. element->note=*note;
  164. /* On assigne l'adresse de l'élément suivant au nouvel élément
  165. */
  166. element->nxt = liste;
  167. liste=element;
  168. /* On retourne la nouvelle liste, i.e. le pointeur sur le
  169. premier élément */
  170. return element;
  171. }
  172. }
  173.  
  174.  
  175.  
  176. #include "main.h"
  177. #include "structures.h"
  178.  
  179. structures* modifier(structures *liste,char *nom,char *prenom,char *classe,float *note)
  180. {
  181. structures *structures2=liste;
  182. while(liste!=NULL)
  183. {
  184. rechercher(nom,prenom);
  185. strcpy(structures2->classe,classe);
  186. structures2->note;
  187. }
  188. }
  189.  
  190.  
  191.  
  192.  
  193. #include "main.h"
  194. #include "structures.h"
  195.  
  196. void decoupage(commande)
  197. {
  198. char *i;
  199. i = strtok(commande," ");
  200. char *nom;
  201. char *liste;
  202. char *prenom;
  203. char *classe;
  204. float *note;
  205. int compteur;
  206.  
  207. nom=strtok(NULL," ");
  208. prenom=strtok(NULL," ");
  209. classe=strtok(NULL," ");
  210. note=strtok(NULL," ");
  211.  
  212. if (strcmp(i,"ajouter")==NULL)
  213. {
  214. ajouter(liste,nom,prenom,classe,note) ;
  215. printf("Vous avez ajoute un eleve.\n\n");
  216. }
  217. // On utilise la fonction ajouter.
  218.  
  219. else if (strcmp(i,"supprimer")==NULL)
  220. {
  221. sup(liste,nom,prenom,classe,note);
  222. printf("Vous avez supprime un eleve.\n\n") ;
  223. }
  224. // On utilise la fonction supprimer.
  225.  
  226.  
  227. else if (strcmp(i,"modifier")==NULL)
  228. {
  229. modifier(liste,nom,prenom,classe,note);
  230. printf("Vous avez remplace un eleve\n\n");
  231. }
  232. // On utilise la fonction modifier.
  233.  
  234. else if (strcmp(i,"afficher")==NULL)
  235. {
  236. afficher(liste,nom,prenom,classe,note);
  237. }
  238. // On definit la fonction afficher.
  239. }
  240.  
  241.  
  242.  
  243. #include "main.h"
  244. #include "structures.h"
  245.  
  246. structures* rechercher(structures *liste, char *nom, char *prenom)
  247. {
  248. structures *recher=liste;
  249. /* Tant que l'on n'est pas au bout de la liste */
  250. while(recher != NULL)
  251. {
  252. if(recher->nom==nom && recher->prenom==prenom)
  253. {
  254. /* Si l'élément a la valeur recherchée, on renvoie son
  255. adresse */
  256. return recher;
  257. }
  258. recher=recher->nxt;
  259. }
  260. return NULL;
  261. }
  262. // Cette fonction permet de retrouver le nom et le prenom pour la fonction modifier.
Add Comment
Please, Sign In to add comment