You are on page 1of 2

#include <stdio.

h>
#include <stdlib.h>

typedef struct
{
int giorno;
char mese[4];
int estratti[5];
}estrazione;

void stampa (estrazione*, int);


void Nnumero(estrazione*, int);
void ambo (estrazione*, int);

int main()
{
int i = 0, dim = 1, scelta;
FILE *input, *output;
estrazione *est;
est = (estrazione*) malloc(sizeof(estrazione));
input = fopen("./BariLotto.txt", "r");
while(!feof(input))
{
fscanf(input, "%d %s %d %d %d %d %d", &est[i].giorno, est[i].mese, &est[i].estratti[0],
&est[i].estratti[1], &est[i].estratti[2], &est[i].estratti[3], &est[i].estratti[4]);
dim++;
est = (estrazione*) realloc(est, dim * sizeof(estrazione));
i++;
}
--dim;
est = (estrazione*) realloc(est, --dim * sizeof(estrazione));
while (1)
{
printf("1)Stampa\n");
printf("2)Estrazioni di un numero\n");
printf("3)Ricerca ambo\n");
printf("4)Frequenze\n");
scanf("%d", &scelta);
switch (scelta)
{
case 1:
stampa(est, dim);
break;
case 2:
Nnumero(est, dim);
break;
}
}
}

void stampa(estrazione* est, int dim)


{
int i;
for(i = 0; i < dim; i++)
printf("%-2d %s %2d %2d %2d %2d %2d\n", est[i].giorno, est[i].mese, est[i].estratti[0],
est[i].estratti[1], est[i].estratti[2], est[i].estratti[3], est[i].estratti[4] );
}

void Nnumero(estrazione* est, int dim)


{
int i = 0, j, cont = 0, num;
system("cls");
printf("Inserisci il numero: ");
scanf("%d", &num);
for(i; i < dim; i++)
for(j = 0; j < 5; j++)
if(est[i].estratti[j] == num)
cont++;
printf("Il numero e' uscito: %d volte\n", cont);
system("PAUSE");
system("cls");
}

void ambo (estrazione* est, int dim)


{
int i, n1, n2;
system("cls");
printf("Inserisci i due numeri: ");
scanf("%d %d", &n1, &n2);

You might also like