从键盘上输入一串字符,将其写入文件myfile.c中,之后将文件中内容输出在屏幕上给用
#include "stdio.h"#include "string.h"
#define ERROR 0
#define n 6
main()
{
FILE *fp;
char chs[n];
char ch[n];
int i;
if ((fp=fopen("myfile.c","w"))==NULL)
{
printf("Can’t open the file ang press any key to exit\n");
getchar();
return ERROR;
}
printf("\nPlease input the string!\n");
scanf("%s",ch);
fputs(ch,fp);
fclose(fp);
getchar();
}