题目原文
利用fopen函数,在d盘根目录下新建文件“Hello.txt”,已知有数组a[100] = “Hi, Lucy!\nHi, Lily!\nHi, Ecuter!”,将数组a的内容写入到txt文件
源代码
#include<stdio.h>
int main()
{
FILE *fp;
fp=fopen("D:\\Hello.txt","w+");
char a[300]="Hi,Lucy!\nHi,Lily!\nHi,Ecuter!";
fseek(fp,4,0);
fputs(a,fp);
printf("%s\n",a);
printf(" %s\n",a);
fclose(fp);
return 0;
}
运行结果