Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <fcntl.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <string.h>
  8. #include <io.h>
  9.  
  10. void fgv();
  11. void fgv1();
  12. void fgv2();
  13. void fgv3();
  14.  
  15. int main()
  16. {
  17.     fgv();
  18.     fgv1();
  19.     fgv2();
  20.     fgv3();
  21.  
  22.     return 0;
  23. }
  24.  
  25. void fgv()
  26. {
  27.     int hnd,c;
  28.  
  29.     hnd=open("adat.txt",O_RDONLY);
  30.  
  31.     while(1)
  32.     {
  33.         c=read(hnd,&c,sizeof(c));
  34.         if(c==-1) return 1;
  35.         else return 0;
  36.         printf("%c",c);
  37.     }
  38.     close(hnd);
  39. }
  40.  
  41. void fgv1()
  42. {
  43.     int hnd, r;
  44.     hnd=open("adat.txt",O_RDONLY);
  45.     r=tell(hnd);
  46.     printf("meret = %i bajt\n\n",r);
  47.     close(hnd);
  48. }
  49.  
  50. void fgv2()
  51. {
  52.     int hnd,i=0,j=0,t[100];
  53.  
  54.     hnd=open("adat.txt",O_CREAT|O_RDWR,S_IREAD|S_IWRITE);
  55.     while(i<100)
  56.     {
  57.         if(j%3==0)
  58.         {
  59.             t[i]=j;
  60.             i++;
  61.         }
  62.         j++;
  63.     }
  64.     for(i=0;i<100;i++)
  65.     {
  66.         write(hnd,&t[i],sizeof(t[i]));
  67.         printf("%i\t",t[i]);
  68.     }
  69.     close(hnd);
  70. }
  71.  
  72. void fgv3()
  73. {
  74.     int hnd,i=0,r,j=0,t[100];
  75.  
  76.     hnd=open("adat.txt",O_CREAT|O_RDWR,S_IREAD|S_IWRITE);
  77.     while(i<100)
  78.     {
  79.         if(j%3==0)
  80.         {
  81.             t[i]=j;
  82.             i++;
  83.         }
  84.         j++;
  85.     }
  86.  
  87.     hnd=open("adat.txt",O_RDONLY);
  88.  
  89.     while(1)
  90.     {
  91.         r=read(hnd,&t[i],sizeof(t[i]));
  92.         if(r>0) break;
  93.         close(hnd);
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement