用c语言实现linux cat

话不多说,直接上代码:

#include <stdio.h>  
void file_copy(FILE * file1,FILE * file2);
int main(int argc,char *argv[])  
{  
    FILE * fp;  
    if(argc == 1)  
        file_copy(stdin,stdout);  
    else  
        while(--argc > 0)  
        {  
            if((fp = fopen(*++argv,"r")) == NULL)  
            {  
                printf("no such file %s
",*argv);  
                return 1;  
            }  
            else  
            {  
                file_copy(fp,stdout);  
                fclose(fp);  
            }  
        }  
    return 0;  
} 
void file_copy(FILE * file1,FILE * file2)  
{  
    int c;  

    while((c = getc(file1)) != EOF)  
    {  
        putc(c,file2);  
    }  
}  
原文地址:https://www.cnblogs.com/hua-sheng/p/12905001.html