Advertisement
Guest User

Untitled

a guest
Jun 30th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <malloc.h>
  5.  
  6. typedef struct Psoci
  7. {
  8. char CodiceFiscale[18];
  9. char Nome[65];
  10. int Sesso;
  11. }Parametri;
  12.  
  13. typedef struct SNodoSoci
  14. {
  15. Parametri InfoSoci;
  16. struct SNodoSoci *nextS;
  17. struct TNodoVincite *nextSottolista;
  18. }TNodoSocio,*t_lista;
  19.  
  20. typedef struct Pvincite
  21. {
  22. char Data[16];
  23. float SoldiVinti;
  24. char CodiceFiscaleVincitore[20];
  25. }ParametriVincite;
  26.  
  27. typedef struct SNodoVincite
  28. {
  29. ParametriVincite InfoVincite;
  30. struct SNodovincite *nextV;
  31. }TNodoVincite,*Sottolista;
  32.  
  33. int fmenu();
  34. void carica(t_lista *list);
  35. void stampa(t_lista list);
  36. void StampaSottoLista(Sottolista lis);
  37.  
  38. int main(void)
  39. {
  40. t_lista lista;
  41. Sottolista sottol;
  42. int scelta;
  43. while (scelta = fmenu())
  44. {
  45. switch (scelta)
  46. {
  47. case 1:
  48. {
  49. system("CLS");
  50.  
  51. lista = NULL;
  52. carica(&lista);
  53. printf("File caricati correttamente.\n");
  54. system("pause");
  55. system("CLS");
  56. break;
  57. }
  58.  
  59. case 2:
  60. {
  61. system("CLS");
  62. stampa(lista);
  63. system("pause");
  64. system("CLS");
  65. break;
  66. }
  67.  
  68. case 3:
  69. {
  70. system("CLS");
  71. StampaSottoLista(lista->nextSottolista);
  72. system("pause");
  73. system("CLS");
  74. break;
  75. }
  76.  
  77. case 4:
  78. {
  79. system("CLS");
  80. system("pause");
  81. system("CLS");
  82. break;
  83. }
  84.  
  85. case 5:
  86. {
  87. system("CLS");
  88. system("pause");
  89. system("CLS");
  90. break;
  91. }
  92.  
  93. case 6:
  94. {
  95. system("CLS");
  96. system("pause");
  97. system("CLS");
  98. break;
  99. }
  100.  
  101. case 7:
  102. {
  103. system("CLS");
  104. system("pause");
  105. system("CLS");
  106. break;
  107. }
  108. case 8:
  109. {
  110. system("CLS");
  111. system("pause");
  112. system("CLS");
  113. break;
  114. }
  115.  
  116. }
  117. }
  118. system("CLS");
  119. printf("Uscita...\n");
  120. }
  121.  
  122. int fmenu()
  123. {
  124. int scelta;
  125. do
  126. {
  127. printf("1. Caricamento da file.\n");
  128. printf("2. Stampa della lista.\n");
  129. printf("3. Inserimento di un nuovo socio.\n");
  130. printf("4. Inserimento di una nuova vincita.\n");
  131. printf("5. Stampa le vincite di tutti i soci superiori ad una cifra fornita.\n");
  132. printf("6. Stampa della vincita media di ogni socio.\n");
  133. printf("7. Cancellazione di un socio (dato il codice fiscale).\n");
  134. printf("8. Salvataggio su file.\n");
  135. printf("0. Esci.\n");
  136. printf(">> ");
  137. scanf("%d", &scelta);
  138. }
  139.  
  140. while (scelta < 0 || scelta>8);
  141.  
  142. return scelta;
  143. }
  144.  
  145. void carica(t_lista *list)
  146. {
  147. Parametri c;
  148. ParametriVincite d;
  149. Sottolista aux;
  150. FILE *f;
  151. FILE *g;
  152. t_lista paux, p, q;
  153.  
  154. f = fopen("Socio.txt", "r");
  155. if (f == NULL)
  156. {
  157. printf("Errore. File inesistente.\n");
  158. exit(0);
  159. }
  160.  
  161. while (fscanf(f, "%s\n%s\n%d", c.CodiceFiscale, c.Nome, &c.Sesso) == 3)
  162. {
  163. paux = (TNodoSocio*)malloc(sizeof(TNodoSocio));
  164. paux->InfoSoci = c;
  165. paux->nextS = NULL;
  166. paux->nextSottolista = NULL;
  167. p = q = *list;
  168.  
  169. if (*list == NULL || strcmp(paux->InfoSoci.CodiceFiscale, p->InfoSoci.CodiceFiscale) == -1)
  170. {
  171. paux->nextS = *list;
  172. *list = paux;
  173. }
  174.  
  175. else
  176. {
  177. p = q = *list;
  178. while (p != NULL && strcmp(paux->InfoSoci.CodiceFiscale, p->InfoSoci.CodiceFiscale) == 1)
  179. {
  180. q = p;
  181. p = p->nextS;
  182. }
  183. q->nextS = paux;
  184. paux->nextS = p;
  185. }
  186.  
  187. g = fopen("Vincita.txt", "r");
  188.  
  189. while (fscanf(g, "%s\n%f\n%s\n", d.Data, &d.SoldiVinti, d.CodiceFiscaleVincitore) == 3)
  190.  
  191. {
  192. if (strcmp(paux->InfoSoci.CodiceFiscale, d.CodiceFiscaleVincitore) == 0)
  193. {
  194. aux = (TNodoVincite*)malloc(sizeof(TNodoVincite));
  195. aux->InfoVincite = d;
  196. aux->nextV = paux->nextSottolista;
  197. paux->nextSottolista = aux;
  198. }
  199. }
  200. }
  201. }
  202.  
  203.  
  204. void stampa(t_lista list)
  205. {
  206. while (list != NULL)
  207. {
  208. printf("%s\n%s\n%d\n\n", list->InfoSoci.CodiceFiscale, list->InfoSoci.Nome, list->InfoSoci.Sesso);
  209. list = list->nextS;
  210. }
  211. }
  212.  
  213. void StampaSottoLista(Sottolista lis)
  214. {
  215. while (lis != NULL)
  216. {
  217. printf("%s\n%f\n%s\n", lis->InfoVincite.Data, lis->InfoVincite.SoldiVinti, lis->InfoVincite.CodiceFiscaleVincitore);
  218. lis = lis->nextV;
  219. }
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement