/*
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씩 받아서 하는거임 ㅠ 일부만 대문자 변환되고 다는 안되는데... 빠가라서 잘 모르겠어요.
님들 왜 자꾸 스크린샷을 뜨는 거죠... 텍스트를 올리라구욧!
리눅스에서 맥으로 복사가안돼요.... ㅠㅜㅜ
눙물
cat [file] | xclip -selection clipboard
xclip설치하고 해결하세양! 아 혹시 ssh클라이언트라 안된다는거?
그럼 다른 ssh클라를 쓰세양!
리눅스에서 글썻음.. 봐주셈 ㅠㅠ 클립보드가 다른가봐 지금 페러렐즈 로 페도라 리눅스쓰는데, 맥으로 복사가 안됨 신기한건 페러렐즈 윈도우에서는 맥 복사 잘됨 ㅋ
세상에 for 문에서 strlen 이라뇨
그러니까 c++을 써야합니다
ㅊ++ 몇줄이면 되는거 극혐이네
저수준을 배우는거라....c로 하지요...
자식만들어서 파이프구현라는 문제네에러나는거 어디서나노
바꼇네 받은걸 대문자 바꾸느느 부분하고 파이프로 부모한테 보내는 부분 바낀거같은데