Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <string.h>
- #define N 50
- typedef struct Mostro {
- char Nome[N];
- char Attributo[N];
- char Tipo[N];
- int Livello;
- int Attacco;
- int Difesa;
- struct Mostro *succ;
- }TMostro;
- struct Mostro* aggiungi_mostro(struct Mostro* testa)
- {
- struct Mostro *nuovo = NULL;
- char nome[N], attributo[N], tipo[N];
- int livello,attacco,difesa;
- nuovo = (struct Mostro*)malloc(sizeof(struct Mostro));
- printf("Inserisci il nome della carta:\n");
- scanf("%s", &nome);
- for(int i=0; i<N;i++)
- nuovo->Nome[i] = nome[i];
- printf("Inserisci l'attributo della carta:\n");
- scanf("%s", &attributo);
- for (int i = 0; i<N; i++)
- nuovo->Attributo[i] = attributo[i];
- printf("Inserisci il tipo di carta:\n");
- scanf("%s", &tipo);
- for (int i = 0; i<N; i++)
- nuovo->Tipo[i] = tipo[i];
- printf("Inserisci il livello della carta:\n");
- scanf("%d", &livello);
- nuovo->Livello = livello;
- printf("Inserisci l'attacco della carta:\n");
- scanf("%d", &attacco);
- nuovo->Attacco = attacco;
- printf("Inserisci la difesa della carta:\n");
- scanf("%d", &difesa);
- nuovo->Difesa = difesa;
- nuovo->succ = testa;
- testa = nuovo;
- return nuovo;
- }
- void stampa(struct Mosto* testa)
- {
- struct Mostro* temp = NULL;
- temp = testa;
- while (temp != NULL)
- {
- printf("\nNome: %s\n", temp->Nome);
- printf("Attributo: %s\n", temp->Attributo);
- printf("Tipo:%s\n", temp->Tipo);
- printf("Livello: %d\n", temp->Livello);
- printf("Attacco: %d\n", temp->Attacco);
- printf("Difesa: %d\n\n\n", temp->Difesa);
- temp = temp->succ;
- }
- }
- int main(void)
- {
- struct Mostro *head = NULL;
- int scelta = 0;
- while(1)
- { printf("***MENU'***\nInserisci:\n1)Aggiungi\n2)Stampa\n3)Cancella Elemento\n4)Esci.\n");
- scanf("%d", &scelta);
- switch (scelta)
- {
- case 1:
- head = aggiungi_mostro(head);
- break;
- case 2:
- stampa(head);
- break;
- case 3:
- break;
- case 4:
- exit(1);
- default:
- printf("\nIl comando inserito non e' accettabile.\n");
- break;
- }
- }
- system("PAUSE");
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement