Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <unistd.h>
- int separate(int fd_in, int fd_out_even, int fd_out_odd) {
- int32_t buf;
- int read_res;
- while ((read_res = read(fd_in, &buf, sizeof(buf))) > 0) {
- if (buf % 2 == 0) {
- if (write(fd_out_even, &buf, sizeof(buf)) != 4) {
- return -1;
- }
- } else {
- if (write(fd_out_odd, &buf, sizeof(buf)) != 4) {
- return -1;
- }
- }
- }
- return read_res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement