Advertisement
Guest User

Untitled

a guest
May 19th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. #################nume.c##################################
  2.  
  3. #include <unistd.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <sys/wait.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <fcntl.h>
  10. #include <errno.h>
  11.  
  12. int main(void)
  13. {
  14. int f_in,f_out;
  15. mkfifo("NameToNumber",0600);
  16. mkfifo("NumberToName",0600);
  17. f_in=open("NameToNumber",O_WRONLY);
  18. f_out=open("NumberToName",O_RDONLY);
  19. char ch='1';
  20. char ch1;
  21. int nume=open("nume.txt",O_RDONLY);
  22. while(ch!='\n')
  23. {
  24. read(nume,&ch,1);
  25. if(ch!='\n')printf("%c",ch);
  26. fflush(stdout);
  27. }
  28. printf(" ");
  29. fflush(stdout);
  30. write(f_in,&ch,1);
  31. while(read(nume,&ch,1))
  32. {
  33. read(f_out,&ch1,1);
  34. while(ch!='\n')
  35. {
  36. printf("%c",ch);
  37. fflush(stdout);
  38. read(nume,&ch,1);
  39. }
  40. printf(" ");
  41. fflush(stdout);
  42. write(f_in,&ch1,1);
  43. }
  44. close(f_in);
  45. close(f_out);
  46. return 0;
  47. }
  48. ##########################telefon.c#####################################################
  49.  
  50.  
  51. #include <unistd.h>
  52. #include <stdio.h>
  53. #include <stdlib.h>
  54. #include <sys/wait.h>
  55. #include <sys/types.h>
  56. #include <sys/stat.h>
  57. #include <fcntl.h>
  58. #include <errno.h>
  59.  
  60. int main(void)
  61. {
  62. int f_in,f_out;
  63. mkfifo("NameToNumber",0600);
  64. mkfifo("NumberToName",0600);
  65. f_in=open("NameToNumber",O_RDONLY);
  66. f_out=open("NumberToName",O_WRONLY);
  67. char ch='1';
  68. char ch1;
  69. int telefon=open("telefon.txt",O_RDONLY);
  70. while(read(telefon,&ch,1))
  71. {
  72. read(f_in,&ch1,1);
  73. while(ch!='\n')
  74. {
  75. printf("%c",ch);
  76. fflush(stdout);
  77. read(telefon,&ch,1);
  78. }
  79. printf("\n");
  80. fflush(stdout);
  81. write(f_out,&ch1,1);
  82. }
  83. close(f_in);
  84. close(f_out);
  85. return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement