C/C++の宿題を片付け ..
562:デフォルトの名無しさん
08/06/14 08:24:18
>>231
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#define MAXLINE 1024
int main(int argc, char *argv[]){
int fd[2];
char line[MAXLINE];
pid_t pid;
if (pipe(fd)<0) exit(1);
if ((pid=fork())>0) { /*parent process */
close(fd[0]);
dup2(fd[1],fileno(stdout));
close(fd[1]);
fgets(line, MAXLINE, stdin);
fputs(line, stdout);
fflush(stdout);
wait(NULL);
exit(0);
} else{ /*child process */
close(fd[1]);
dup2(fd[0],fileno(stdin));
close(fd[0]);
fgets(line, MAXLINE, stdin);
fputs(line, stdout);
exit(0);
}
}
次ページ最新レス表示スレッドの検索類似スレ一覧話題のニュースおまかせリスト▼オプションを表示暇つぶし2ch
5023日前に更新/317 KB
担当:undef