#include #define MAXD 256 //Max lung descrizione operazione #define MAXOP 1000 //Num max operazioni typedef struct { int num; //Numero progressivo dell'operazione double imp; //Importo dell'operazione char desc[MAXD]; //Descrizione dell'operazione } Oper; int main(int argc, char **argv) { //Funzioni invocate void scriviop(FILE *, Oper*, int); double uscite(Oper *, int); double entrate(Oper *, int); double saldo(Oper *, int); Oper *maxuscita(Oper *, int); Oper *maxentrata(Oper *, int); if (argc<=2) { printf("Errore: manca il nome di uno dei due file.\n"); return -1; } FILE *f; if ((f=fopen(argv[1],"r"))==NULL) // Apre il primo file in lettura { printf("Errore: non riesco ad aprire il file %s.\n", argv[1]); return -1; } //Variabili locali Oper listop[MAXOP]; int tot; //totale operazioni //Importa le operazioni dal file for (tot=0; tot=MAXOP) ) return; for (int i=0; inum,lop->imp,lop->desc); } double uscite(Oper *lop, int tot) //Calcola uscita totale di un lista di tot { //operazioni if (lop==NULL) return 0; double u=0; for (;tot>=0;tot--) if (lop[tot].imp < 0) u+=lop[tot].imp; return u; } double entrate(Oper *lop, int tot) //Calcola entrata totale di un lista di tot { //operazioni if (lop==NULL) return 0; double e=0; for (;tot>=0;tot--) if (lop[tot].imp>0) e+=lop[tot].imp; return e; } Oper *maxuscita(Oper *lop, int tot) { if (lop==NULL) return NULL; Oper *max=lop; for (;tot>=0;tot--) if (lop[tot].imp < (max->imp)) max=lop+tot; if ( (max->imp) < 0 ) return max; return NULL; } Oper *maxentrata(Oper *lop, int tot) { if (lop==NULL) return NULL; Oper *max=lop; for (;tot>=0;tot--) if (lop[tot].imp > (max->imp)) max=lop+tot; if ( (max->imp) > 0 ) return max; return NULL; } double saldo(Oper *lop, int tot) // Calcola saldo { if (lop==NULL) return 0; double saldo=0; for (;tot>=0;tot--) saldo+=lop[tot].imp; return saldo; }