Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
1,088
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define N 50
  5.  
  6. typedef struct Mostro {
  7. char Nome[N];
  8. char Attributo[N];
  9. char Tipo[N];
  10. int Livello;
  11. int Attacco;
  12. int Difesa;
  13. struct Mostro *succ;
  14. }TMostro;
  15.  
  16.  
  17.  
  18. struct Mostro* aggiungi_mostro(struct Mostro* testa)
  19. {
  20. struct Mostro *nuovo = NULL;
  21. char nome[N], attributo[N], tipo[N];
  22. int livello,attacco,difesa;
  23. nuovo = (struct Mostro*)malloc(sizeof(struct Mostro));
  24. printf("Inserisci il nome della carta:\n");
  25. scanf("%s", &nome);
  26. for(int i=0; i<N;i++)
  27. nuovo->Nome[i] = nome[i];
  28. printf("Inserisci l'attributo della carta:\n");
  29. scanf("%s", &attributo);
  30. for (int i = 0; i<N; i++)
  31. nuovo->Attributo[i] = attributo[i];
  32. printf("Inserisci il tipo di carta:\n");
  33. scanf("%s", &tipo);
  34. for (int i = 0; i<N; i++)
  35. nuovo->Tipo[i] = tipo[i];
  36. printf("Inserisci il livello della carta:\n");
  37. scanf("%d", &livello);
  38. nuovo->Livello = livello;
  39. printf("Inserisci l'attacco della carta:\n");
  40. scanf("%d", &attacco);
  41. nuovo->Attacco = attacco;
  42. printf("Inserisci la difesa della carta:\n");
  43. scanf("%d", &difesa);
  44. nuovo->Difesa = difesa;
  45. nuovo->succ = testa;
  46. testa = nuovo;
  47. return nuovo;
  48.  
  49.  
  50. }
  51. /*
  52. struct Mostro* elimina_mostro(struct Mostro* testa);
  53. { struct Mostro*temp = NULL;
  54. struct Mostro*comp = NULL;
  55. char nome[N];
  56. int scelta = 0; i;
  57. printf("Inserisci il nome del mostro da eliminare:\n");
  58. scanf("%s", &nome);
  59. while (temp != NULL);
  60. {
  61. for(i=0;i<N;i++)
  62. if (comp->Nome[i] = nome[i])
  63. {
  64. printf("La carta che si vuole elminare e' questa?\n");
  65. printf("\nNome: %s\n", temp->Nome);
  66. printf("Attributo: %s\n", temp->Attributo);
  67. printf("Tipo:%s\n", temp->Tipo);
  68. printf("Livello: %d\n", temp->Livello);
  69. printf("Attacco: %d\n", temp->Attacco);
  70. printf("Difesa: %d\n\n\n", temp->Difesa);
  71. printf("Inserisci 1 per SI, 0 per NO");
  72. scanf("%d", &scelta);
  73. if (scelta == 1)
  74. {
  75.  
  76. }
  77. }
  78. temp = temp->succ;
  79. }
  80. }*/
  81.  
  82.  
  83. void stampa(struct Mosto* testa)
  84. {
  85. struct Mostro* temp = NULL;
  86. temp = testa;
  87. while (temp != NULL)
  88. {
  89. printf("\nNome: %s\n", temp->Nome);
  90. printf("Attributo: %s\n", temp->Attributo);
  91. printf("Tipo:%s\n", temp->Tipo);
  92. printf("Livello: %d\n", temp->Livello);
  93. printf("Attacco: %d\n", temp->Attacco);
  94. printf("Difesa: %d\n\n\n", temp->Difesa);
  95. temp = temp->succ;
  96. }
  97. }
  98.  
  99. struct Mostro* Cerca(struct Mostro* testa)
  100. {
  101. int a = 0, i = 0;
  102. struct Mostro* nuovo;
  103. nuovo = (struct Mostro*)malloc(sizeof(struct Mostro));
  104. char nome[N];
  105. printf("Inserisci l'elemento da cercare:\n");
  106. scanf("%s", &nome);
  107. nuovo = testa;
  108. while (nuovo != NULL)
  109. a = strncmp(nome, nuovo->Nome, N);
  110. if (a == 0)
  111. {
  112. printf("Il mostro cercato e':\n");
  113. printf("%s\n", nuovo->Nome);
  114. printf("%s\n", nuovo->Attributo);
  115. printf("%s\n", nuovo->Tipo);
  116. printf("%d\n", nuovo->Livello);
  117. printf("%d\n", nuovo->Attacco);
  118. printf("%d\n", nuovo->Difesa);
  119. }
  120. else
  121. {printf("Non è il %d elemento", i);
  122. i++;
  123. }
  124. nuovo = nuovo->succ;
  125. }
  126.  
  127. struct Mostro* Elimina(struct Mostro*testa)
  128. {
  129. struct Mostro* nuovo;
  130. nuovo = (struct Mostro*) malloc(sizeof(struct Mostro));
  131. nuovo=testa
  132.  
  133.  
  134. }
  135.  
  136.  
  137. int main(void)
  138. {
  139. struct Mostro *head = NULL;
  140. int scelta = 0;
  141.  
  142. while(1)
  143. { printf("***MENU'***\nInserisci:\n1)Aggiungi\n2)Cerca\n3)Stampa\n4)Esci.\n");
  144. scanf("%d", &scelta);
  145.  
  146. switch (scelta)
  147. {
  148. case 1:
  149. head = aggiungi_mostro(head);
  150. break;
  151. case 2:
  152. Cerca(head);
  153. break;
  154. case 3:
  155. stampa(head);
  156. break;
  157. case 4:
  158. exit(1);
  159. default:
  160. printf("\nIl comando inserito non e' accettabile.\n");
  161. break;
  162.  
  163. }
  164. }
  165.  
  166.  
  167. system("PAUSE");
  168. return 0;
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement