/*
1. open a text file, create an output file; create two pipes(pipe1, 2)
2. fork two children
3. main : read 10 bytes and then put them into pipe 1 until EOF
4. child1 : get 10 bytes from pipe 1 and convert them into capital letters; and then put them into pipe2 until pipe1 closed;
5. child2 : get 10 bytes from pipe2 and write them into the output file until pipe2 closed
6. main process waits for deaths of children.

*/
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>
#include <ctype.h>
int main()
{
    int fd1[2], fd2[2]; //  descripter for two pipe
    int input;
    if(fd1>=0){ printf("open success!\n");} // file open check
    else{ printf("open fail\n");}    // exception
    int output;
    pipe(fd1);
    pipe(fd2);
    int n;   
    int a;   
    char buf[10];    // initialize buffer use in file r/w
    int status;    // initialize status   
    if((fork()) == 0) //fork start! child
    {
        close(fd1[1]);
        while((n = read(fd1[0], buf, sizeof(buf))) != 0)
        {
            for( a = 0; a< strlen(buf); a++)
            {buf[a] = (char)toupper(buf[a]);
             write(fd2[1], &buf, sizeof(buf));}
        }
        close(fd2[1]);
        if((fork()) == 0)  //sub_child
        {  close(fd2[1]);
           output = creat("copytxt.txt", 0777);
           while((n = read(fd2[0], buf, sizeof(buf))) != 0) write(output, &buf, sizeof(buf));
           close(fd2[0]);
           close(output);   
           exit(0);
        }
    wait(&status); //wait for death of child
    exit(0);
    }
    else //parents
    { input = open("./test.txt", 0);
      close(fd1[0]);
      while((n = read(input, buf, sizeof(buf))) != 0) write(fd1[1], &buf, sizeof(buf));
      close(input);
      close(fd1[1]);
        wait(&status);
     }
   
return 0;
}

전부다 대문자로 변해야하는데


조건 : char 10씩 받아서 하는거임 ㅠ 일부만 대문자 변환되고 다는 안되는데... 빠가라서 잘 모르겠어요.