Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #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;
- }
- /*
- struct Mostro* elimina_mostro(struct Mostro* testa);
- { struct Mostro*temp = NULL;
- struct Mostro*comp = NULL;
- char nome[N];
- int scelta = 0; i;
- printf("Inserisci il nome del mostro da eliminare:\n");
- scanf("%s", &nome);
- while (temp != NULL);
- {
- for(i=0;i<N;i++)
- if (comp->Nome[i] = nome[i])
- {
- printf("La carta che si vuole elminare e' questa?\n");
- 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);
- printf("Inserisci 1 per SI, 0 per NO");
- scanf("%d", &scelta);
- if (scelta == 1)
- {
- }
- }
- temp = temp->succ;
- }
- }*/
- 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;
- }
- }
- struct Mostro* Cerca(struct Mostro* testa)
- {
- int a = 0, i = 0;
- struct Mostro* nuovo;
- nuovo = (struct Mostro*)malloc(sizeof(struct Mostro));
- char nome[N];
- printf("Inserisci l'elemento da cercare:\n");
- scanf("%s", &nome);
- nuovo = testa;
- while (nuovo != NULL)
- a = strncmp(nome, nuovo->Nome, N);
- if (a == 0)
- {
- printf("Il mostro cercato e':\n");
- printf("%s\n", nuovo->Nome);
- printf("%s\n", nuovo->Attributo);
- printf("%s\n", nuovo->Tipo);
- printf("%d\n", nuovo->Livello);
- printf("%d\n", nuovo->Attacco);
- printf("%d\n", nuovo->Difesa);
- }
- else
- {printf("Non è il %d elemento", i);
- i++;
- }
- nuovo = nuovo->succ;
- }
- struct Mostro* Elimina(struct Mostro*testa)
- {
- struct Mostro* nuovo;
- nuovo = (struct Mostro*) malloc(sizeof(struct Mostro));
- nuovo=testa
- }
- int main(void)
- {
- struct Mostro *head = NULL;
- int scelta = 0;
- while(1)
- { printf("***MENU'***\nInserisci:\n1)Aggiungi\n2)Cerca\n3)Stampa\n4)Esci.\n");
- scanf("%d", &scelta);
- switch (scelta)
- {
- case 1:
- head = aggiungi_mostro(head);
- break;
- case 2:
- Cerca(head);
- break;
- case 3:
- stampa(head);
- 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