LINUX C 輸出重定向例子

 

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>

int main(int argc,char *argv)
{  
   FILE *fp = fopen("./a.out","a+b");
   if(fp == NULL)
   {
       //      
   }
        
   void *p = stdout;  
   stdout = fp;
   printf("%s\r\n","輸出重定向");
   fclose(fp);  
   stdout = p;
   printf("%s\r\n","finish");
    return 0;
}

 

發佈了84 篇原創文章 · 獲贊 26 · 訪問量 36萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章