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: datainput.c
- Itt található az ellenõrzött adatbeolvasó és a fájlmegnyitó függvény.*/
- struct Videogames;
- void datainput(void)
- {
- int correct = 0;
- FILE *fp; /* File-ra mutató pointer.*/
- fp=fopen("games.txt","at"); /* Fájl megnyitása*/
- if (fp == NULL)
- {
- printf("Error: cannot open file."); /*Hibaüzenet kiírása, ha a fájl nem nyitható meg.*/
- return;
- }
- Videogames v;
- /*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.*/
- do {
- printf("\nPlease type the title of the game: ");
- scanf("%s", v.name);
- if (strlen(v.name) < 2 || strlen(v.name) > 30) /*A játék nevének ellenõrzött beolvasása*/
- {
- correct = 0;
- printf("Error: The name of the game's length must be between 2 and 30 characters!");
- }
- else
- {
- correct = 1;
- }
- } while(correct != 1);
- correct = 0;
- do {
- printf("\nType the category of the game: ");
- scanf("%s", v.category);
- if (strlen(v.category) < 3 || strlen(v.category) > 6) /*A játék kategóriájának ellenõrzött beolvasása*/
- {
- correct = 0;
- printf("Error: The length of the game's category must be between 3 and 6 characters!");
- }
- else
- {
- correct = 1;
- }
- } while(correct != 1);
- correct = 0;
- do {
- printf("\nType it's release date: ");
- scanf("%d", &v.releasedate);
- if (v.releasedate < 1980 || v.releasedate > 2016) /*A játék megjelenési idõpontjának ellenõrzött beolvasása*/
- {
- correct = 0;
- printf("Error: The length of the release date must be between 1980 and 2016 characters!");
- }
- else
- {
- correct = 1;
- }
- } while(correct != 1);
- correct = 0;
- do {
- printf("\nThe paying method of the game is: ");
- scanf("%s", v.payingmethod);
- if (strlen(v.payingmethod) < 4 || strlen(v.payingmethod) > 15) /*A játék fizetési rendszerének ellenõrzött beolvasása*/
- {
- correct = 0;
- printf("Error: The length of the paying method must be between 4 and 15 characters!");
- }
- else
- {
- correct = 1;
- }
- } while(correct != 1);
- correct = 0;
- do {
- printf("\nThe developer of the game is: ");
- scanf("%s", v.developer);
- if (strlen(v.developer) < 3 || strlen(v.developer) > 20) /*A játék fejlesztõcégének ellenõrzött beolvasása*/
- {
- correct = 0;
- printf("Error: The length of the developer's corporation name must be between 3 and 20 characters!");
- }
- else
- {
- correct = 1;
- }
- } while(correct != 1);
- correct = 0;
- do {
- printf("\nThe disk space requirements of this game: ");
- scanf("%s", v.diskspacerequirement); /*A játék helyigényének ellenõrzött beolvasása*/
- if (strlen(v.diskspacerequirement) < 3 || strlen(v.diskspacerequirement) > 5)
- {
- correct = 0;
- printf("Error: The length of the disk space requirements must be between 3 and 5 characters!");
- }
- else
- {
- correct = 1;
- }
- } while(correct != 1);
- correct = 0;
- do {
- printf("\nThe pirce of this game: ");
- scanf("%d", &v.price);
- if (v.price < 1000 || v.price > 50000) /*A játék árának ellenõrzött beolvasása*/
- {
- correct = 0;
- printf("Error: The price of the game must be between 1 000 and 50 000!");
- }
- else
- {
- correct = 1;
- }
- } while(correct != 1);
- correct = 0;
- do {
- printf("\nIs this game available nowadays?: ");
- 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*/
- if (strlen(v.availability) < 9 || strlen(v.availability) > 13)
- {
- correct = 0;
- printf("Error: The length of the availability must be between 9 and 13 characters!");
- }
- else
- {
- correct = 1;
- }
- } while(correct != 1);
- correct = 0;
- do {
- printf("\nDo we have some copies in the warehouse?: ");
- scanf("%s", v.warehouse); /*Ez ellenõrzötten beolvassa azt, hogy a játék van-e raktáron jelenleg, vagy sem.*/
- if (strlen(v.warehouse) < 8 || strlen(v.warehouse) > 15)
- {
- correct = 0;
- printf("Error: The length of this information must be between 9 and 13 characters!");
- }
- else
- {
- correct = 1;
- }
- } while(correct != 1);
- /*Ez a fájl tartalmának kiíratása.*/
- 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);
- fclose(fp); /*Fájl bezárása*/
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment