#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/wait.h>

#define BUFSIZE 256

static void replace_vowels(char *w)
{
    for (int i = 0; w[i]; i++) {
        switch (tolower((unsigned char)w[i])) {
            case 'a': case 'e': case 'i': case 'o': case 'u':
                w[i] = '*';
        }
    }
}

int main(void)
{
    int fd[2];
    if (pipe(fd) == -1) { perror("pipe"); exit(EXIT_FAILURE); }

    pid_t pid = fork();
    if (pid == -1) { perror("fork"); exit(EXIT_FAILURE); }

    if (pid == 0) {
        close(fd[1]);

        FILE *fin = fdopen(fd[0], "r");
        if (!fin) { perror("fdopen"); exit(EXIT_FAILURE); }

        char word[BUFSIZE];
        while (fscanf(fin, "%255s", word) == 1) {
            replace_vowels(word);
            printf("[figlio] %s\n", word);
            fflush(stdout);
        }
        fclose(fin);
        exit(EXIT_SUCCESS);
    }

    close(fd[0]);

    char word[BUFSIZE];
    while (scanf("%255s", word) == 1) {
        if (word[0] == '#') {
            printf("[padre]  %s\n", word + 1);
            fflush(stdout);
        } else {
            dprintf(fd[1], "%s\n", word);
        }
    }
    close(fd[1]);   /* EOF per il figlio */
    wait(NULL);
    return 0;
}
