Telaryon

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

Mar 18th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.60 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: datainput.c
  8. Itt található az  ellenõrzött adatbeolvasó és a fájlmegnyitó függvény.*/
  9.  
  10. struct Videogames;
  11.  
  12. void datainput(void)
  13. {
  14.     int correct = 0;
  15.  
  16.     FILE *fp;                       /* File-ra mutató pointer.*/
  17.     fp=fopen("games.txt","at");     /* Fájl megnyitása*/
  18.  
  19.     if (fp == NULL)
  20.     {
  21.         printf("Error: cannot open file.");     /*Hibaüzenet kiírása, ha a fájl nem nyitható meg.*/
  22.         return;
  23.     }
  24.     Videogames v;
  25.  
  26.     /*Innen kezdõdnek az adatok ellenõrzött beolvasása. Minden beovlasásnál hibaüzenetet fog kiírni, ha a kritériumnak nem megfelelõ adatot viszünk be.*/
  27.  
  28.     do {
  29.         printf("\nPlease type the title of the game: ");
  30.         scanf("%s", v.name);
  31.         if (strlen(v.name) < 2 || strlen(v.name) > 30)      /*A játék nevének ellenõrzött beolvasása*/
  32.         {
  33.             correct = 0;
  34.             printf("Error: The name of the game's length must be between 2 and 30 characters!");
  35.         }
  36.         else
  37.         {
  38.             correct = 1;
  39.         }
  40.     } while(correct != 1);
  41.  
  42.     correct = 0;
  43.     do {
  44.         printf("\nType the category of the game: ");
  45.         scanf("%s", v.category);
  46.         if (strlen(v.category) < 3 || strlen(v.category) > 6)       /*A játék kategóriájának ellenõrzött beolvasása*/
  47.         {
  48.             correct = 0;
  49.             printf("Error: The length of the game's category must be between 3 and 6 characters!");
  50.         }
  51.         else
  52.         {
  53.             correct = 1;
  54.         }
  55.     } while(correct != 1);
  56.  
  57.     correct = 0;
  58.     do {
  59.         printf("\nType it's release date: ");
  60.         scanf("%d", &v.releasedate);
  61.         if (v.releasedate < 1980 || v.releasedate > 2016)       /*A játék megjelenési idõpontjának ellenõrzött beolvasása*/
  62.         {
  63.             correct = 0;
  64.             printf("Error: The length of the release date must be between 1980 and 2016 characters!");
  65.         }
  66.         else
  67.         {
  68.             correct = 1;
  69.         }
  70.     } while(correct != 1);
  71.  
  72.     correct = 0;
  73.     do {
  74.         printf("\nThe paying method of the game is: ");
  75.         scanf("%s", v.payingmethod);
  76.         if (strlen(v.payingmethod) < 4 || strlen(v.payingmethod) > 15)      /*A játék fizetési rendszerének ellenõrzött beolvasása*/
  77.         {
  78.             correct = 0;
  79.             printf("Error: The length of the paying method must be between 4 and 15 characters!");
  80.         }
  81.         else
  82.         {
  83.             correct = 1;
  84.         }
  85.     } while(correct != 1);
  86.  
  87.     correct = 0;
  88.     do {
  89.         printf("\nThe developer of the game is: ");
  90.         scanf("%s", v.developer);
  91.         if (strlen(v.developer) < 3 || strlen(v.developer) > 20)        /*A játék fejlesztõcégének ellenõrzött beolvasása*/
  92.         {
  93.             correct = 0;
  94.             printf("Error: The length of the developer's corporation name must be between 3 and 20 characters!");
  95.         }
  96.         else
  97.         {
  98.             correct = 1;
  99.         }
  100.     } while(correct != 1);
  101.  
  102.     correct = 0;
  103.     do {
  104.             printf("\nThe disk space requirements of this game: ");
  105.             scanf("%s", v.diskspacerequirement);                        /*A játék helyigényének ellenõrzött beolvasása*/
  106.             if (strlen(v.diskspacerequirement) < 3 || strlen(v.diskspacerequirement) > 5)
  107.             {
  108.                 correct = 0;
  109.                 printf("Error: The length of the disk space requirements must be between 3 and 5 characters!");
  110.             }
  111.             else
  112.             {
  113.                 correct = 1;
  114.             }
  115.         } while(correct != 1);
  116.  
  117.     correct = 0;
  118.     do {
  119.         printf("\nThe pirce of this game: ");
  120.         scanf("%d", &v.price);
  121.         if (v.price < 1000 || v.price > 50000)          /*A játék árának ellenõrzött beolvasása*/
  122.         {
  123.             correct = 0;
  124.             printf("Error: The price of the game must be between 1 000 and 50 000!");
  125.         }
  126.         else
  127.         {
  128.             correct = 1;
  129.         }
  130.     } while(correct != 1);
  131.  
  132.     correct = 0;
  133.     do {
  134.             printf("\nIs this game available nowadays?: ");
  135.             scanf("%s", v.availability);                        /*A játék elérhetõségének(Meg lehet-e még vásárolni vagy sem) ellenõrzött beolvasása*/
  136.             if (strlen(v.availability) < 9 || strlen(v.availability) > 13)
  137.             {
  138.                 correct = 0;
  139.                 printf("Error: The length of the availability must be between 9 and 13 characters!");
  140.             }
  141.             else
  142.             {
  143.                 correct = 1;
  144.             }
  145.         } while(correct != 1);
  146.  
  147.     correct = 0;
  148.     do {
  149.             printf("\nDo we have some copies in the warehouse?: ");
  150.             scanf("%s", v.warehouse);                                   /*Ez ellenõrzötten beolvassa azt, hogy a játék van-e raktáron jelenleg, vagy sem.*/
  151.             if (strlen(v.warehouse) < 8 || strlen(v.warehouse) > 15)
  152.             {
  153.                 correct = 0;
  154.                 printf("Error: The length of this information must be between 9 and 13 characters!");
  155.             }
  156.             else
  157.             {
  158.                 correct = 1;
  159.             }
  160.         } while(correct != 1);
  161.  
  162.         /*Ez a fájl tartalmának kiíratása.*/
  163.  
  164.     fprintf(fp, "%s %s %d %s %s %s %d %s %s\n", v.name, v.category, v.releasedate, v.payingmethod, v.developer, v.diskspacerequirement, v.price, v.availability, v.warehouse);
  165.  
  166.     fclose(fp);     /*Fájl bezárása*/
  167.     return;
  168. }
Advertisement
Add Comment
Please, Sign In to add comment