#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main(int argc, char*argv[])
{
const int MAX=100;
FILE*f;
FILE*f2;
char riga[MAX+1];
char codprod[32];
float costouno, valatt=0.0, valprec=0.0;
int quantita, trovato=0;
if(argc!=5)
{
printf(“numero di parametri errato\n”);
exit(1);
}
f=fopen(argv[1],”r”);
if(f==NULL)
{
printf(“impossibile aprire il file\n”);
exit(1);
}
while(fgets(riga,MAX,f)!=NULL)
{
sscanf(riga,”%s %f %d”, &codprod, &costouno, &quantita);
if(strcmp(codprod,argv[3])==0)
{
printf(“valore complessivo precedente: %.2f\nvalore complessivo attuale: %.2f”, costouno*(float)quantita, costouno*(float)(quantita+atoi(argv[4])) );
trovato=1;
f2=fopen(argv[2],”a”);
if(f2==NULL)
{
printf(“impossibile aprire il file\n”);
exit(1);
}
fprintf(f2,”%s %.2f %d\n”, codprod, costouno, quantita+atoi(argv[4]) );
fclose(f2);
}
else
{
f2=fopen(argv[2],”a”);
if(f2==NULL)
{
printf(“impossibile aprire il file\n”);
exit(1);
}
fprintf(f2,”%s %.2f %d\n”, codprod, costouno, quantita);
fclose(f2);
}
}
if(trovato==0)
{
printf(“prodotto %s non presente in magazzino\n”, argv[3]);
}
exit(0);
}
