Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <errno.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <unistd.h>
- int notAVowel(char c) {
- char vowels[10] = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};
- int index = 0;
- while (index < 10) {
- if (c == vowels[index])
- return 0;
- index++;
- }
- return 1;
- }
- int main(int argc, char **argv) {
- int pipeUno[2];
- pid_t pid1, pid2;
- if (argc != 2)
- perror("Invalid argument number(inset one)"), exit(-1);
- if (pipe(pipeUno) < 0)
- perror("Pipe"), exit(-1);
- if ((pid1 = fork()) < 0)
- perror("Fork"), exit(-1);
- if (pid1 == 0) { /*figlio 1*/
- char buffer[1];
- int fileDesc;
- close(pipeUno[1]);
- if ((fileDesc = open(argv[1], O_WRONLY | O_APPEND)) < 0)
- perror("Can't open file (writing)"), exit(-1);
- while (read(pipeUno[0], buffer, 1)) {
- if (notAVowel(buffer[0])) {
- write(fileDesc, buffer, 1);
- }
- }
- close(pipeUno[1]);
- close(fileDesc);
- } else {
- if ((pid2 = fork()) < 0)
- perror("Fork 2"), exit(-1);
- if (pid2 == 0) { /* figlio 2*/
- int fileDescriptor;
- char buffer[1];
- if ((fileDescriptor = open(argv[1], O_RDONLY)) < 0)
- perror("Can't open file"), exit(-1);
- close(pipeUno[0]);
- while (read(fileDescriptor, buffer, 1)) {
- write(pipeUno[1], buffer, 1);
- }
- close(pipeUno[1]);
- close(fileDescriptor);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement