Telaryon

Egyszerű Nyilvántartószoftver példa III. rész

Mar 18th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <conio.h>
  5. #include "structure.h"
  6.  
  7. /*File name: list.c
  8. Itt van a lista függvénye*/
  9.  
  10. struct Videogames;
  11.  
  12. void list(void)
  13. {
  14.     int lines = 0;
  15.     int i;
  16.     int sumprice = 0;
  17.     float averagegamepirces;
  18.  
  19.     FILE *fp;
  20.     fp = fopen("games.txt","rt");       /*Fájl megnyitása*/
  21.  
  22.     if (fp == NULL)
  23.     {
  24.         printf("Error: cannot open file.");         /*Hibaüzenet, ha a fájl nem nyitható meg*/
  25.         return;
  26.     }
  27.  
  28.     Videogames v;
  29.     while(1)
  30.     {
  31.         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);
  32.         if(!feof(fp))
  33.         {
  34.             lines++;
  35.         }
  36.         else
  37.         {
  38.             break;
  39.         }
  40.     }
  41.  
  42.     rewind(fp);
  43.  
  44.     for (i=0; i<=lines; i++)
  45.     {
  46.          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);
  47.          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",
  48.          v.name, v.category, v.releasedate, v.payingmethod, v.developer, v.diskspacerequirement, v.price, v.availability, v.warehouse);
  49.  
  50.          sumprice += v.price;   /*A játékok árainak összegzése*/
  51.     }
  52.  
  53.     averagegamepirces = sumprice / i;           /*Átlag játékárak kiszámolása.*/
  54.  
  55.     printf("\n\nThe average prices of the games: %2.2lf\n", averagegamepirces);         /*Átlaag játékárak kiíratása*/
  56.     printf("The overall price of the games: %d", sumprice);                             /*A játékok árainak az összegének a kiíratása*/
  57.     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.*/
  58.  
  59.     fclose(fp);
  60.     return;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment