Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <signal.h>
- #include <unistd.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #define VOWELS "aeiou"
- int main(int argc, char *argv[]) {
- if (argc != 2) {
- fprintf(stderr, "Wrong usage!\n");
- exit(1);
- }
- int pbuff[2];
- if (pipe(pbuff)) {
- perror("pipe");
- exit(1);
- }
- pid_t pid = fork();
- if (pid == -1) {
- perror("");
- exit(-1);
- }
- if (pid == 0) {//kid
- close(pbuff[0]);
- int fd = open(argv[1], O_RDONLY);
- if (fd < 0) {
- perror("open");
- exit(1);
- }
- char ch;
- while (read(fd, &ch, 1)) {
- if (strchr(VOWELS, ch)) {
- write(pbuff[1], &ch, 1);
- }
- }
- close(fd);
- close(pbuff[1]);
- exit(0);
- }
- close(pbuff[1]);
- char ch;
- int cnt = 0;
- while (read(pbuff[0], &ch, 1)) {
- cnt++;
- }
- printf("Cnt: %d\n", cnt);
- close(pbuff[0]);
- int stat;
- wait(&stat);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement