Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct {
- char Nome_sport[25];
- int Ore;
- }Sport;
- typedef struct {
- int ID;
- Sport *dati_sport;
- }Info;
- void Aggiungi(int,int,Info *);
- int main()
- {
- int scelta;
- int x = 1;
- Info informazioni[10]; // รจ fissato ( ho 10 classi )
- int scelta_id = 1;
- int i = 0;
- do{
- printf("\n[1] Aggiungi \t[0] Esci \n");
- do{
- scanf("%d",&scelta);
- if( scelta < 0 || scelta > 1 )
- {
- printf("\nScelta non valida...\n");
- printf("[1] Aggiungi \t[0] Esci \n");
- }
- }while(scelta < 0 || scelta > 1 );
- switch(scelta){
- case 1 :
- Aggiungi(i,scelta_id,informazioni);
- i++;
- break;
- case 0 :
- x = 2;
- break;
- }
- }while(x==1);
- printf("\nID: %d",informazioni[scelta_id].ID);
- printf("\nNome sport : %s",informazioni[scelta_id].dati_sport[0].Nome_sport);
- printf("\nNome sport : %s",informazioni[scelta_id].dati_sport[1].Nome_sport);
- return 0;
- }
- void Aggiungi(int i,int scelta_id,Info *informazioni)
- {
- Sport *dati = NULL;
- informazioni[scelta_id].ID = scelta_id;
- dati = (Sport *)malloc(1 * sizeof(Sport)); //allochiamo spazio per la struttura Sport
- if(dati==NULL){
- printf("Errore");
- exit(1);
- }
- printf("\nInserisci i dati :");
- printf("\nNome sport :");
- getchar();
- gets(dati[i].Nome_sport);
- printf("\nInserisci le ore :");
- scanf("%d",&dati[i].Ore);
- informazioni[scelta_id].dati_sport[i] = dati[i];
- free(dati);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement