Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <conio.h>
- #include "structure.h"
- /*File name: list.c
- Itt van a lista függvénye*/
- struct Videogames;
- void list(void)
- {
- int lines = 0;
- int i;
- int sumprice = 0;
- float averagegamepirces;
- FILE *fp;
- fp = fopen("games.txt","rt"); /*Fájl megnyitása*/
- if (fp == NULL)
- {
- printf("Error: cannot open file."); /*Hibaüzenet, ha a fájl nem nyitható meg*/
- return;
- }
- Videogames v;
- while(1)
- {
- fscanf(fp, "%s %s %d %s %s %s %d %s %s", v.name, v.category, &v.releasedate, v.payingmethod, v.developer, v.diskspacerequirement, &v.price, v.availability, v.warehouse);
- if(!feof(fp))
- {
- lines++;
- }
- else
- {
- break;
- }
- }
- rewind(fp);
- for (i=0; i<=lines; i++)
- {
- fscanf(fp, "%s %s %d %s %s %s %d %s %s", v.name, v.category, &v.releasedate, v.payingmethod, v.developer, v.diskspacerequirement, &v.price, v.availability, v.warehouse);
- printf("\nName:\t%s,\tCategory:\t%s,\tRelease date:\t%d,\tPaying method:\t%s,\tThe game's developer:\t%s,\n\tDisk space requirement:\t%s,\tPrice:\t%d,\tAvailable:\t%s,\tIn store:\t%s\n",
- v.name, v.category, v.releasedate, v.payingmethod, v.developer, v.diskspacerequirement, v.price, v.availability, v.warehouse);
- sumprice += v.price; /*A játékok árainak összegzése*/
- }
- averagegamepirces = sumprice / i; /*Átlag játékárak kiszámolása.*/
- printf("\n\nThe average prices of the games: %2.2lf\n", averagegamepirces); /*Átlaag játékárak kiíratása*/
- printf("The overall price of the games: %d", sumprice); /*A játékok árainak az összegének a kiíratása*/
- printf("\nThere are %d game in our the database.", i); /*Ez írja ki azt, hogy hány játék van összesen az adatbázisban.*/
- fclose(fp);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment