C 语言文件拷贝

相关的方法:

int fputs(const char*s,FILE *stream);

int gets(char *s,int size,FILE *stream);

具体代码如下

/**
*@author cody
*@date 2014-08-09
*@description copy text file
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char const *argv[])
{
    
    FILE *in = fopen("copy.c","r");
    FILE *out = fopen("copy_1.c","w+");
    if(in == NULL || out == NULL){
        perror("open file error");
        exit(0);
    }

    int size = 20;
    char buf[20];
    while(fgets(buf,20,in) != NULL){
        fputs(buf,out);
    }

    fclose(in);
    fclose(out);


    return 0;
}
原文地址:https://www.cnblogs.com/cody1988/p/3901147.html