Facebook
From Thundering Peccary, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 190
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7.  
  8.  
  9. #define FIFO "my_fifo"
  10. char szyfr(char input)
  11. {
  12.         return input +3;
  13. }
  14.  
  15. int main(){
  16.                
  17.         //umask(0);
  18.     mkfifo(FIFO, 0666);
  19.                        
  20.         if(fork()==0)
  21.         {
  22.                 char text[256];
  23.        
  24.                 fprintf(stdout, "Podaj ciag znakow: ");
  25.                 scanf("%s",text);
  26.                 //printf("TEXT: %s",text);
  27.                 //FILE *plik
  28.                 //plik=open("zadanko","r");
  29.                
  30.                
  31.                 FILE *fp;
  32.                 fp=fopen(FIFO,"w");
  33.                 fputs(text,fp);
  34.                 fclose(fp);
  35.                
  36.  
  37.                 printf("wyslano tekst %s\n",text);
  38.         }
  39.         if(fork()==0)
  40.         {
  41.                 char text2[128];
  42.                 FILE *fp;
  43.                 fp=fopen(FIFO,"r");
  44.                 fgets(text2,128,fp);
  45.                 sleep(4);
  46.                 printf("Odebrano text: %s\n",text2);
  47.                 fclose(fp);
  48.                 int i;
  49.                 printf("tu jestem\n");
  50.                 for(i=0;i<10;i++)
  51.                 //while(text2[i]!=0)
  52.                 {       if(text2[i]==0)
  53.                         {break;}
  54.                         printf("%d\n",text2[i]);
  55.                         text2[i]=szyfr(text2[i]);
  56.                        
  57.                 }
  58.                 printf("Zaszyfrowany text: %s\n", text2);
  59.                
  60.         }
  61.         return 0;
  62. }