建立一个磁盘文件,文件名由键盘输入,文件内容也由键盘输入。文件内容的输入以"*"作为输入结束标志。
参考答案:#include<stdio.h>
#include<stdlib.h>
main()
char ch,fname[20];
FILE *fp;
scanf("%s",fname);
if((fp=fopen(fname,"w"))==NULL)/*如果fp为空则创建文件失败*/
{
printf("Can not open the file required.");
exit(0);
}
ch=getchar();
while(ch=’*’)
{
fputc(ch,fp);
putchar(ch);
eh=getchar();
}/*对文件输入内容*/
fclose(fp);/*关闭文件*/
}