Guest User

Untitled

a guest
May 25th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define IMEDAT "dionice.dat"
  6.  
  7. typedef struct {
  8.     int redni_broj;
  9.     char naziv_postaje[13+1];
  10.     int udaljenost;
  11. } klasa;
  12.  
  13. int citaj_dat(FILE *dat) {
  14.  
  15.     klasa autoput;
  16.  
  17.     printf("r.br. Naplatna postaja  udaljenost(km)\n====================================\n");
  18.     while (fread(&autoput, sizeof(autoput), 1, dat) == 1)
  19.     {
  20.         printf("%3d\t%12s\t   %6.3f\n", autoput.redni_broj, autoput.naziv_postaje, (float) autoput.udaljenost / 1000);
  21.     }
  22.     return autoput.redni_broj;
  23. }
  24.  
  25. int main () {
  26.  
  27.     FILE *inputfile = NULL;
  28.     int broj_dionica;
  29.     char ime[13+1];
  30.  
  31.     if ((inputfile = fopen(IMEDAT, "rb")) == NULL)
  32.     {
  33.         printf("Doslo do je do pogreske u otvaranju datoteke %s.\n", IMEDAT);
  34.         exit(0);
  35.     }
  36.  
  37.     broj_dionica = citaj_dat(inputfile);
  38.  
  39.     printf("\n\nBroj procitanih dionica: %d.\n", broj_dionica);
  40.  
  41.     fclose(inputfile);
  42.  
  43.     return 0;
  44. }
Add Comment
Please, Sign In to add comment