Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define IMEDAT "cestarine.dat"
- typedef struct {
- int redni_broj;
- char naziv_postaje[13+1];
- int cestarina;
- } klasa;
- int citaj_dat(FILE *dat) {
- klasa autoput;
- printf("r.br. Naplatna postaja Cestarina(kn)\n====================================\n");
- while (fread(&autoput, sizeof(autoput), 1, dat) == 1)
- {
- printf("%3d\t%12s\t %6.2f\n", autoput.redni_broj, autoput.naziv_postaje, (float) autoput.cestarina);
- }
- return autoput.redni_broj;
- }
- void ispisi(FILE *dat){
- klasa autoput;
- printf("\n\n Najveci redni broj je: ");
- printf("\n%3d\t%12s\t %6.2f\n", autoput.redni_broj, autoput.naziv_postaje, (float) autoput.cestarina);
- }
- void ispisi_1(FILE *dat){
- klasa autoput;
- int n;
- printf("\nUnesi cestarinu: ");
- scanf("%d", &n);
- while (fread(&autoput, sizeof(autoput), 1, dat) == 1);
- {
- printf("%3d\t%12s\t %6.2f\n", autoput.redni_broj, autoput.naziv_postaje, (float) autoput.cestarina);
- }
- }
- int main () {
- FILE *inputfile = NULL;
- int broj_dionica;
- char ime[13+1];
- if ((inputfile = fopen(IMEDAT, "rb")) == NULL)
- {
- printf("Doslo do je do pogreske u otvaranju datoteke %s.\n", IMEDAT);
- exit(0);
- }
- broj_dionica = citaj_dat(inputfile);
- ispisi(inputfile);
- ispisi_1(inputfile);
- printf("\n\n\nBroj procitanih dionica: %d.\n", broj_dionica);
- fclose(inputfile);
- return 0;
- }
Add Comment
Please, Sign In to add comment