Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5. typedef struct s_cliente{
  6. char cliente[21];
  7. }t_cliente;
  8.  
  9. typedef struct s_nodo{
  10. t_cliente info;
  11. struct s_nodo *next;
  12. }t_nodo;
  13.  
  14. typedef struct s_coda{
  15. t_nodo *primo;
  16. t_nodo *ultimo;
  17. }codaClienti;
  18.  
  19. typedef struct s_racc{
  20. char destinatario[21];
  21. int ricevuta;
  22. }t_racc;
  23.  
  24. typedef struct nodo{
  25. t_racc informazione;
  26. struct nodo *next;
  27. }nodo, *Lista;
  28.  
  29. typedef struct s2{
  30. char cliente[21];
  31. int sportello;
  32. int numero;
  33. }t_cliente_serviti;
  34.  
  35. typedef struct s3{
  36. t_cliente_serviti info;
  37. struct s3 *next;
  38. Lista sottolista;
  39. }nodoCoda;
  40.  
  41. typedef struct Coda{
  42. nodoCoda *primo;
  43. nodoCoda *ultimo;
  44. }Coda;
  45.  
  46. //CODA E LISTA INIT
  47.  
  48. void InitCoda(codaClienti *c, Coda *pc){
  49. c->primo=c->ultimo=NULL;
  50. pc->primo=pc->ultimo=NULL;
  51. }
  52.  
  53. int CodaVuota(codaClienti c){
  54. return(c.primo==NULL);
  55. }
  56.  
  57. void MakeNullList(Lista *l){
  58. *l=NULL;
  59. }
  60.  
  61. int EmptyLista(Lista *l){
  62. return(l==NULL);
  63. }
  64.  
  65. //FUNZIONE CANCELLA
  66.  
  67. void cancella(codaClienti *c){
  68. codaClienti aux;
  69. if(c->primo!=NULL){
  70. aux.primo=c->primo;
  71. c->primo=c->primo->next;
  72. free(aux.primo);
  73. }
  74. }
  75.  
  76. //CARICO IN CODA
  77.  
  78. void inserisci_in_coda(codaClienti *c, t_cliente elem){
  79. t_nodo *aux;
  80. aux=(t_nodo*)malloc(sizeof(t_nodo));
  81. aux->info=elem;
  82. aux->next=NULL;
  83. if(!CodaVuota(*c)){
  84. c->primo=c->ultimo=aux;
  85. }
  86. else{
  87. c->ultimo->next=aux;
  88. c->ultimo=aux;
  89. }
  90. }
  91.  
  92. codaClienti InCoda(codaClienti *c, char file[]){
  93. t_cliente aux;
  94. FILE *fp=NULL;
  95. fp=fopen(file, "r");
  96. if(fp==NULL){
  97. printf("Errore apertura file");
  98. exit(1);
  99. }
  100. while(!feof(fp)){
  101. fscanf(fp, "%s", aux.cliente);
  102. inserisci_in_coda(c, aux);
  103. }
  104. return *c;
  105. }
  106.  
  107. //STAMPA
  108.  
  109. void stampa(codaClienti c){
  110. t_cliente aux;
  111. if(c.primo!=NULL){
  112. printf("/// %s ///", aux.cliente);
  113. c.primo=c.primo->next;
  114. }
  115. }
  116.  
  117. //MENU
  118.  
  119. int menu(){
  120. int scelta=0;
  121. printf("Premi 0 per uscire");
  122. printf("Premi 1 per inserire in coda");
  123. printf("Premi 4 per stampare");
  124. scanf("%d", &scelta);
  125. return scelta;
  126. }
  127.  
  128. int main(){
  129. int scelta=0;
  130. FILE *fp;
  131. fp=fopen("Clienti.txt", "r");
  132. t_cliente cliente;
  133. codaClienti C;
  134. Lista L;
  135. Coda Coda;
  136. do{
  137. scelta=menu();
  138. switch(scelta){
  139. case 1:{
  140. InCoda(&C, "Clienti.txt");
  141. break;
  142. }
  143. }
  144. }while(scelta!=0);
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement