1、
#include <stdio.h>
#include <string.h>
int main(int argc, const char *argv[])
{
FILE *file=fopen("./fprintf.txt","r");
FILE *file1=fopen("./txt.txt","r+");
if(file==NULL)
return -1;
int res;
char buf;
while(1){
res = fscanf(file,"%c",&buf);
if(EOF == res)
break;
fprintf(file1,"%c",buf);
}
fclose(file);
fclose(file1);
return 0;
}
运行结果
#include <stdio.h>
#include <string.h>
int main(int argc, const char *argv[])
{
FILE *file=fopen("./fprintf.txt","r");
FILE *file1=fopen("./txt.txt","r+");
if(file==NULL)
return -1;
char res;
while(1){
res = fgetc(file);
if(EOF == res)
break;
fputc(res,file1);
}
fclose(file);
fclose(file1);
return 0;
}
运行结果
#include <stdio.h>
#include <string.h>
int main(int argc, const char *argv[])
{
FILE *file=fopen("./fprintf.txt","r");
FILE *file1=fopen("./txt.txt","r+");
if(file==NULL)
return -1;
char res[2];
while(fgets(res,sizeof(res),file)!=NULL){
fputs(res,file1);
}
fclose(file);
fclose(file1);
return 0;
}
运行结果