1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
FILE *fp;
struct magazzino magazzinoStato;
int codice;
if ((fp = fopen("magazzino.dat", "r+")) == NULL)
printf("Non possibile aprire il file !!!.\n");
else
{
printf("Immetti i codice identificativo del prodotto (da 1 a 300 )\n");
scanf("%d", &codice);
while (!feof(fp))
{
fread(&magazzinoStato, sizeof(struct magazzino), 1, fp);
if (magazzinoStato.codice == codice)
{
printf("%-15d%-15s%-15s%-15.2f%-15.2f%-15d%-15d\n",magazzinoStato.codice,magazzinoStato.nome,magazzinoStato.produttore,magazzinoStato.costo, magazzinoStato.vendita, magazzinoStato.giacenza, magazzinoStato.venduti);
printf("\nInserire nuova giacenza: ");
fflush(stdin);
scanf("%d", &magazzinoStato.giacenza);
printf("\nInserire nuovo valore dei prodotti venduti: ");
fflush(stdin);
scanf("%d", &magazzinoStato.venduti);
fseek(fp, -sizeof(struct magazzino), SEEK_CUR);
fwrite(&magazzinoStato, sizeof(struct magazzino), 1, fp);
fclose(fp);
printf("\nModifica Effettuata");
break;
}}}
|