linuxc吧 关注:46贴子:175
  • 3回复贴,共1

关于dup2引发的文件缓冲区的思考

只看楼主收藏回复

百思不得姐呀


1楼2013-07-02 20:45回复
    我写了个这样的例子:
    #include<stdio.h>
    #include<unistd.h>
    #include<sys/types.h>
    #include<sys/stat.h>
    int main(void)
    {
    int fd;
    fd = open("txt",O_RDWR | O_CREAT | O_TRUNC );
    if(fd == -1)
    {
    perror("open");
    return -1;
    }
    printf("******");
    dup2(fd,STDOUT_FILENO);
    printf("######\n");
    close(1);
    return 0;
    }
    终端无输出,txt里“******######”,为什么呢


    3楼2013-07-02 20:54
    收起回复
      表示不懂。。
      -----低调奢华V880,喂自己袋盐╭(╯ε╰)╮


      IP属地:安徽来自Android客户端4楼2014-01-21 00:31
      回复