C 語言文件拷貝

 

相關的方法:spa

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

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

 

具體代碼以下code

 

/**
*@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;
}
相關文章
相關標籤/搜索