日期:2014-05-16 浏览次数:20890 次
#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include <stdlib.h>
int main()
{
int fd2;
fd2 = open("lsttic.out",O_WRONLY
------解决方案--------------------
O_CREAT, 0777);
if(fd2 < 0) {
perror("open error");
exit(-1);
}
if(dup2(fd2,1)==-1)
{
perror("dup error!!!");
exit(0);
}
printf("hello world!!!\n");
close(fd2);
printf("hello world!!!\n");
return 0;
}
#include<stdio.h>
#include <string.h>
#include<unistd.h>
#include<fcntl.h>
#include <stdlib.h>
#include <string.h>
#define MSG "HAHAHA\n"
int main()
{
int fd;
printf("ttyname is:%s\n", ttyname(0));
printf("ttyname is:%s\n", ttyname(1));
if((fd = open(ttyname(0), O_WRONLY)) < 0) {
perror("open error");
return -1;
}
printf("new fd is %d\n", fd);