fputs写一个字符串到文件中去
函数原型
#include<stdio.h>
int fputs(const char *str,FILE *stream);
#include<stdio.h>
/*
*需求:把文件test.c拷贝到新文件test_copy.c中, 本文件为test.c
*/
int main (void) {
FILE * file1;
FILE * file2;
char line[64];
//打开文件
file1 = fopen ("test.c","r");
file2 = fopen("test_copy.c","w");
if (!file1 || !file2) {
printf("文件打开失败\n");
return 1;
}
while (fgets(line,sizeof(line),file1)) {
fputs(line,file2);
}
folose(file1);
fclose(file2);
return 0;
}