#include "include/apue.h"
#include <stdio.h>
#include <dirent.h>
int main(int argc, char* argv[]) {
int n;
char buf[BUFFSIZE];
while((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0) {
if (write(STDOUT_FILENO, buf, n) != n) {
err_sys("write error!");
}
}
if (n < 0) {
err_sys("read error");
}
}
终端运行:./test > temp1
然后在终端输入内容,程序就会写入到temp1文件中;(如果temp1没有将被自动创建)
终端运行:./test < temp1 > temp2
运行后,temp1文件内的内容就会被写入temp2文件中;