Advertisement
Guest User

Untitled

a guest
May 24th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Napisati fju koja upisuje brojeve u binarnu datoteku
  2. // Procitati brojeve iz binarne datoteke
  3. #include <stdio.h>
  4. #define naziv_datoteke "c:\\Podaci\\proizvodi.dat"
  5.  
  6. void citanje_bin(void){
  7.     int broj;
  8.     FILE * datoteka;
  9.     datoteka=fopen(naziv_datoteke, "rb");
  10.     if (datoteka==NULL){
  11.         printf("Doslo je do greske! \n");
  12.         return;
  13.    
  14.    
  15.    
  16.     }while (fread(&broj, sizeof(int), 1, datoteka)!=0){
  17.                 printf("%d\n");
  18.    
  19.     }
  20.         fclose(datoteka);
  21.    
  22.  
  23.  
  24.  
  25.  
  26. }
  27. void upis_bin(void){
  28.  
  29.     int broj;
  30.     FILE *datoteka;
  31.     char c = 'D';
  32.     datoteka = fopen(naziv_datoteke, "wb");
  33.     if (datoteka==NULL) {
  34.    
  35.         printf("Doslo je do greske!\n");
  36.         return;
  37.    
  38.     }  
  39.     while (c=='D' || c=='d') {
  40.    
  41.         printf("Unesite broj: ");
  42.         scanf("%d", &broj);
  43.         fflush(stdin);
  44.         fwrite(&broj, sizeof(int), 1, datoteka);
  45.         printf("Novi unos (D/N)? ");
  46.         scanf("%c", &c);
  47.         fflush(stdin);
  48.    
  49.     }
  50.     fclose(datoteka);
  51. }
  52.  
  53. int main (void) {
  54.     //upis_bin();
  55.     citanje_bin();
  56.         return 0;
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement