Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <limits.h>
- int main()
- {
- unsigned short dtime, atime, fnumber, stops, time;
- unsigned int let;
- char days[7+1], from [3+1], to[3+1], fcode [3+1], fclass [10+1], acode[2+1];
- char meal, dual;
- FILE *file = NULL;
- file = fopen("flight.csv", "w");
- if (file==NULL) {
- printf ("Error!");
- return 1;
- }
- while(1) {
- do {
- printf ("Unesi kod leta:(0 za kraj)\n");
- scanf ("%d", &let);
- if (let==0)
- return 1;
- } while (let<0 || let>UINT_MAX);
- do {
- printf ("Unesi broj trajanja leta u danima:\n");
- scanf ("%s", &days);
- } while (strlen(days)>7);
- do {
- printf ("Odakle:\n");
- scanf ("%s", &from);
- } while (strlen(from)>3);
- do {
- printf ("Kamo:\n");
- scanf ("%s", &to);
- } while (strlen(to)>3);
- do {
- printf ("Ocekivano vrijeme polijetanja:\n");
- scanf ("%hd", &dtime);
- } while (dtime<0 || dtime>USHRT_MAX);
- do {
- printf ("Ocekivano vrijeme slijetanja:\n");
- scanf ("%hd", &atime);
- } while (atime<0 || atime>USHRT_MAX);
- do {
- printf ("Kod aviokompanije:\n");
- scanf ("%s", &acode);
- } while (strlen(acode)>2);
- do {
- printf ("Broj leta:\n");
- scanf ("%hd", &fnumber);
- } while (fnumber<0 || fnumber>USHRT_MAX);
- do {
- printf ("Klasa leta:\n");
- scanf ("%s", &fclass);
- } while (strlen(fclass)>10);
- do {
- printf ("Kod zrakoplova:\n");
- scanf ("%s", &fcode);
- } while (strlen(fcode)>3);
- printf ("Kod hrane:\n");
- scanf (" %c", &meal);
- do {
- printf ("Broj zaustavljanja:\n");
- scanf ("%hd", &stops);
- } while (stops<0 || stops>USHRT_MAX);
- printf ("Dvostruki?(Y/N):\n");
- do {
- scanf (" %c", &dual);
- } while (dual!='Y' && dual!='N');
- do {
- printf ("Ukupno vrijeme putovanja:\n");
- scanf ("%hd", &time);
- } while (time<0 || time>USHRT_MAX);
- fprintf(file,"%d;%s;%s;%s;%hd;%hd;%s;%hd;%s;%s;%c;%hd;%c;%hd\n",
- let,days,from,to,dtime,atime,acode,fnumber,fclass,fcode,meal,stops,dual,time);
- }
- fclose(file);
- return 0;
- }
Add Comment
Please, Sign In to add comment