Guest User

Untitled

a guest
May 26th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define IMEDAT "cestarine.dat"
  6.  
  7. typedef struct {
  8. int redni_broj;
  9. char naziv_postaje[13+1];
  10. int cestarina;
  11. } klasa;
  12.  
  13. int citaj_dat(FILE *dat) {
  14.  
  15. klasa autoput;
  16.  
  17. printf("r.br. Naplatna postaja Cestarina(kn)\n====================================\n");
  18. while (fread(&autoput, sizeof(autoput), 1, dat) == 1)
  19. {
  20. printf("%3d\t%12s\t %6.2f\n", autoput.redni_broj, autoput.naziv_postaje, (float) autoput.cestarina);
  21. }
  22. return autoput.redni_broj;
  23. }
  24.  
  25. void ispisi(FILE *dat){
  26. klasa autoput;
  27.  
  28.  
  29. printf("\n\n Najveci redni broj je: ");
  30. printf("\n%3d\t%12s\t %6.2f\n", autoput.redni_broj, autoput.naziv_postaje, (float) autoput.cestarina);
  31.  
  32. }
  33.  
  34. void ispisi_1(FILE *dat){
  35. klasa autoput;
  36. int n;
  37. printf("\nUnesi cestarinu: ");
  38. scanf("%d", &n);
  39.  
  40.  
  41.  
  42. while (fread(&autoput, sizeof(autoput), 1, dat) == 1);
  43. {
  44. printf("%3d\t%12s\t %6.2f\n", autoput.redni_broj, autoput.naziv_postaje, (float) autoput.cestarina);
  45. }
  46.  
  47.  
  48. }
  49.  
  50.  
  51. int main () {
  52.  
  53. FILE *inputfile = NULL;
  54. int broj_dionica;
  55. char ime[13+1];
  56.  
  57. if ((inputfile = fopen(IMEDAT, "rb")) == NULL)
  58. {
  59. printf("Doslo do je do pogreske u otvaranju datoteke %s.\n", IMEDAT);
  60. exit(0);
  61. }
  62.  
  63. broj_dionica = citaj_dat(inputfile);
  64. ispisi(inputfile);
  65. ispisi_1(inputfile);
  66. printf("\n\n\nBroj procitanih dionica: %d.\n", broj_dionica);
  67.  
  68. fclose(inputfile);
  69.  
  70. return 0;
  71. }
Add Comment
Please, Sign In to add comment