Advertisement
pasholnahuy

file odd/even

Dec 26th, 2023 (edited)
1,292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <unistd.h>
  3.  
  4. int separate(int fd_in, int fd_out_even, int fd_out_odd) {
  5.     int32_t buf;
  6.     int read_res;
  7.     while ((read_res = read(fd_in, &buf, sizeof(buf))) > 0) {
  8.         if (buf % 2 == 0) {
  9.             if (write(fd_out_even, &buf, sizeof(buf)) != 4) {
  10.                 return -1;
  11.             }
  12.         } else {
  13.             if (write(fd_out_odd, &buf, sizeof(buf)) != 4) {
  14.                 return -1;
  15.             }
  16.         }
  17.     }
  18.     return read_res;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement