Advertisement
Guest User

Untitled

a guest
May 20th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.71 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <sys/stat.h>
  5. #include <sys/types.h>
  6. #include <fcntl.h>
  7. #include <errno.h>
  8.  
  9. int main()
  10. {
  11.     int f=open("nume.txt",O_RDONLY);
  12.     char ch='y';
  13.     int readcode;
  14.     int p[2],q[2];
  15.     mkfifo("p",0600);
  16.     mkfifo("q",0600);
  17.     q[1]=open("q",O_WRONLY);
  18.     p[0]=open("p",O_RDONLY);
  19.    
  20.    
  21.  
  22.     while(1)
  23.     {
  24.       read(p[0],&ch,1);
  25.  
  26.         while(1)
  27.         {
  28.             readcode=read(f,&ch,1);
  29.             if(readcode==0)
  30.                 break;
  31.             if(ch=='\n')
  32.                 break;
  33.             printf("%c",ch);
  34.         }
  35.  
  36.  
  37.         printf("  ");
  38.        
  39.         if(readcode==0)
  40.             break;
  41.            
  42.         write(q[1],&ch,1);
  43.        
  44.  
  45.     }
  46.  
  47.     close(p[0]);
  48.     close(q[1]);
  49. }
  50.  
  51.  
  52.  
  53. /////////////////////////////////////////////////////
  54.  
  55. #include <unistd.h>
  56. #include <stdio.h>
  57. #include <stdlib.h>
  58. #include <sys/stat.h>
  59. #include <sys/types.h>
  60. #include <fcntl.h>
  61. #include <errno.h>
  62.  
  63.  
  64. int main()
  65. {
  66.     int f=open("telefon.txt",O_RDONLY);
  67.     char ch='x';
  68.     int p[2],q[2],readcode;
  69.     mkfifo("p",0600);
  70.     mkfifo("q",0600);
  71.     q[0]=open("q",O_RDONLY);
  72.     p[1]=open("p",O_WRONLY);
  73.    
  74.    
  75.  
  76.     write(p[1],&ch,1);
  77.     while(1)
  78.     {
  79.        
  80.      read(q[0],&ch,1);
  81.    
  82.         while(1)
  83.         {
  84.             readcode=read(f,&ch,1);
  85.             if(readcode==0)
  86.                 break;
  87.             if(ch=='\n')
  88.                 break;
  89.             printf("%c",ch);
  90.         }
  91.  
  92.        
  93.         printf("\n");
  94.        
  95.         if(readcode==0)
  96.             break;
  97.  
  98.        
  99.         write(p[1],&ch,1);
  100.        
  101.  
  102.  
  103.     }
  104.  
  105.     close(p[1]);
  106.     close(q[0]);
  107.  
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement