no1. copy file with func Fscanf and func Fprintf:
#include <stdio.h>
int main(int argc, const char *argv[])
{
FILE* fp=fopen("./bbb.c","r");
FILE* fpp=fopen("./ccc.c","w");
if(NULL==fp)
{
perror("fopen");
return -1;
}
if(NULL==fpp)
{
perror("fopen");
return -1;
}
char buf;
while(fscanf(fp,"%c",&buf)!=EOF)
{
fprintf(fpp,"%c",buf);
}
fclose(fp);
fclose(fpp);
return 0;
}
no.2 copy file with func Fgetc and func Fputc
#include <stdio.h>
int main(int argc, const char *argv[])
{
FILE* fp=fopen("./bbb.c","r");
FILE* fpp=fopen("./ddd.c","w");
if(NULL==fp)
{
perror("fopen");
return -1;
}
if(NULL==fpp)
{
perror("fopen");
return -1;
}
char buf;
while((buf=fgetc(fp))!=EOF)
{
fputc(buf,fpp);
}
fclose(fp);
fclose(fpp);
return 0;
}
no.3 copy file with func Fgets and func Fputs
#include <stdio.h>
int main(int argc, const char *argv[])
{
FILE* fp=fopen("./bbb.c","r");
FILE* fpp=fopen("./eee.c","w");
if(NULL==fp)
{
perror("fopen");
return -1;
}
if(NULL==fpp)
{
perror("fopen");
return -1;
}
char buf[128]="";
while((fgets(buf,sizeof(buf),fp))!=NULL)
{
fputs(buf,fpp);
}
fclose(fp);
fclose(fpp);
return 0;
}