Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #define N 50
  4.  
  5. typedef struct Mostro {
  6. char Nome[N];
  7. char Attributo[N];
  8. char Tipo[N];
  9. int Livello;
  10. int Attacco;
  11. int Difesa;
  12. struct Mostro *succ;
  13. }TMostro;
  14.  
  15. struct Mostro* aggiungi_mostro(struct Mostro* testa)
  16. {
  17. struct Mostro *nuovo = NULL;
  18. char nome[N], attributo[N], tipo[N];
  19. int livello,attacco,difesa;
  20. nuovo = (struct Mostro*)malloc(sizeof(struct Mostro));
  21. printf("Inserisci il nome della carta:\n");
  22. scanf("%s", &nome);
  23. for(int i=0; i<N;i++)
  24. nuovo->Nome[i] = nome[i];
  25. printf("Inserisci l'attributo della carta:\n");
  26. scanf("%s", &attributo);
  27. for (int i = 0; i<N; i++)
  28. nuovo->Attributo[i] = attributo[i];
  29. printf("Inserisci il tipo di carta:\n");
  30. scanf("%s", &tipo);
  31. for (int i = 0; i<N; i++)
  32. nuovo->Tipo[i] = tipo[i];
  33. printf("Inserisci il livello della carta:\n");
  34. scanf("%d", &livello);
  35. nuovo->Livello = livello;
  36. printf("Inserisci l'attacco della carta:\n");
  37. scanf("%d", &attacco);
  38. nuovo->Attacco = attacco;
  39. printf("Inserisci la difesa della carta:\n");
  40. scanf("%d", &difesa);
  41. nuovo->Difesa = difesa;
  42. nuovo->succ = testa;
  43. testa = nuovo;
  44. return nuovo;
  45. }
  46.  
  47. void stampa(struct Mosto* testa)
  48. {
  49. struct Mostro* temp = NULL;
  50. temp = testa;
  51. while (temp != NULL)
  52. {
  53. printf("\nNome: %s\n", temp->Nome);
  54. printf("Attributo: %s\n", temp->Attributo);
  55. printf("Tipo:%s\n", temp->Tipo);
  56. printf("Livello: %d\n", temp->Livello);
  57. printf("Attacco: %d\n", temp->Attacco);
  58. printf("Difesa: %d\n\n\n", temp->Difesa);
  59. temp = temp->succ;
  60. }
  61. }
  62.  
  63. int main(void)
  64. {
  65. struct Mostro *head = NULL;
  66. int scelta = 0;
  67.  
  68. while(1)
  69. { printf("***MENU'***\nInserisci:\n1)Aggiungi\n2)Stampa\n3)Cancella Elemento\n4)Esci.\n");
  70. scanf("%d", &scelta);
  71.  
  72. switch (scelta)
  73. {
  74. case 1:
  75. head = aggiungi_mostro(head);
  76. break;
  77. case 2:
  78. stampa(head);
  79. break;
  80. case 3:
  81. break;
  82. case 4:
  83. exit(1);
  84. default:
  85. printf("\nIl comando inserito non e' accettabile.\n");
  86. break;
  87.  
  88. }
  89. }
  90.  
  91.  
  92. system("PAUSE");
  93. return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement