Advertisement
Guest User

Untitled

a guest
May 24th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #define nazivdatoteke "c:\\Podaci\\proizvodi.dat"
  3.  
  4. void upisibin(void){
  5. int broj;
  6. FILE *datoteka;
  7. char c='d';
  8. datoteka=fopen(nazivdatoteke,"wb");
  9. if (datoteka==NULL){
  10.     printf("doslo je do greske\n");
  11.     return;
  12. }
  13. while(c=='d' || c=='D'){
  14.     printf("Unesi broj: ");
  15.     scanf("%d",&broj);
  16.     fflush(stdin);
  17.     fwrite(&broj,sizeof(int),1,datoteka);
  18.     printf("da li zelite da nastavite unos?" );
  19.     scanf("%c",&c);
  20.     fflush(stdin);
  21. }
  22.  
  23. }
  24. void citanjebin (void){
  25.     FILE *datoteka;
  26.     int broj;
  27.     datoteka=fopen(nazivdatoteke,"rb");
  28.     if (datoteka==NULL){
  29.     printf("doslo je do greske\n");
  30.     return;
  31. }
  32.     while(fread(&broj,sizeof(int),1,datoteka)!=NULL){
  33.         printf("%d\n",broj);
  34.  
  35.  
  36.     }
  37.     fclose(datoteka);
  38. }
  39.  
  40. int main (void){
  41.     //upisibin();
  42.     citanjebin();
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement