Guest User

Untitled

a guest
May 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <limits.h>
  5.  
  6. int main()
  7. {
  8.     unsigned short dtime, atime, fnumber, stops, time;
  9.     unsigned int let;
  10.     char days[7+1], from [3+1], to[3+1], fcode [3+1], fclass [10+1], acode[2+1];
  11.     char meal, dual;
  12.  
  13.     FILE *file = NULL;
  14.     file = fopen("flight.csv", "w");
  15.     if (file==NULL) {
  16.         printf ("Error!");
  17.         return 1;
  18.     }
  19.  
  20.     while(1) {
  21.  
  22.         do {
  23.             printf ("Unesi kod leta:(0 za kraj)\n");
  24.             scanf ("%d", &let);
  25.  
  26.             if (let==0)
  27.                 return 1;
  28.         } while (let<0 || let>UINT_MAX);
  29.  
  30.         do {
  31.             printf ("Unesi broj trajanja leta u danima:\n");
  32.             scanf ("%s", &days);
  33.         } while (strlen(days)>7);
  34.  
  35.         do {
  36.             printf ("Odakle:\n");
  37.             scanf ("%s", &from);
  38.         } while (strlen(from)>3);
  39.  
  40.         do {
  41.             printf ("Kamo:\n");
  42.             scanf ("%s", &to);
  43.         } while (strlen(to)>3);
  44.  
  45.         do {
  46.             printf ("Ocekivano vrijeme polijetanja:\n");
  47.             scanf ("%hd", &dtime);
  48.         } while (dtime<0 || dtime>USHRT_MAX);
  49.  
  50.         do {
  51.             printf ("Ocekivano vrijeme slijetanja:\n");
  52.             scanf ("%hd", &atime);
  53.         } while (atime<0 || atime>USHRT_MAX);
  54.  
  55.         do {
  56.             printf ("Kod aviokompanije:\n");
  57.             scanf ("%s", &acode);
  58.         } while (strlen(acode)>2);
  59.  
  60.         do {
  61.             printf ("Broj leta:\n");
  62.             scanf ("%hd", &fnumber);
  63.         } while (fnumber<0 || fnumber>USHRT_MAX);
  64.  
  65.         do {
  66.             printf ("Klasa leta:\n");
  67.             scanf ("%s", &fclass);
  68.         } while (strlen(fclass)>10);
  69.  
  70.         do {
  71.             printf ("Kod zrakoplova:\n");
  72.             scanf ("%s", &fcode);
  73.         } while (strlen(fcode)>3);
  74.  
  75.         printf ("Kod hrane:\n");
  76.         scanf (" %c", &meal);
  77.  
  78.         do {
  79.             printf ("Broj zaustavljanja:\n");
  80.             scanf ("%hd", &stops);
  81.         } while (stops<0 || stops>USHRT_MAX);
  82.  
  83.         printf ("Dvostruki?(Y/N):\n");
  84.         do {
  85.             scanf (" %c", &dual);
  86.         } while (dual!='Y' && dual!='N');
  87.  
  88.         do {
  89.             printf ("Ukupno vrijeme putovanja:\n");
  90.             scanf ("%hd", &time);
  91.         } while (time<0 || time>USHRT_MAX);
  92.  
  93.         fprintf(file,"%d;%s;%s;%s;%hd;%hd;%s;%hd;%s;%s;%c;%hd;%c;%hd\n",
  94.                 let,days,from,to,dtime,atime,acode,fnumber,fclass,fcode,meal,stops,dual,time);
  95.     }
  96.  
  97.     fclose(file);
  98.     return 0;
  99. }
Add Comment
Please, Sign In to add comment