69,371
社区成员
发帖
与我相关
我的任务
分享
#include "stdio.h"
void write(void)
{ int i=0;
char ch[100];
FILE *fp;
if((fp=fopen("c:\\c1.txt","w+"))==NULL)
{
printf("文件不存在!");
getchar();
//exit(0);
}
printf("please enter the data:\n");
scanf("%s",ch);
while(ch[i]!='\0')
{
fputc(ch[i++],fp);
}
fclose(fp);
}
void read(void)
{
char ch;
FILE *fp;
if((fp=fopen("c:\\c1.txt","r"))==NULL)
{
printf("文件不存在!");
getchar();
//exit(0);
}
ch=fgetc(fp);
printf("the data is \n");
while(ch!=EOF)
{
printf("%c",ch);
ch=fgetc(fp);
}
printf("\n");
fclose(fp);
}
void main()
{
write();
read();
getchar();
}
#include "stdio.h"
void read()
{
char ch;
FILE *fp;
if((fp=fopen("c:\\c1.txt","r"))==NULL)
{
printf("文件不存在!");
getchar();
exit(0);
}
ch=fgetc(fp);
while(ch!=EOF)
{
printf("%c",ch);
ch=fgetc(fp);
}
fclose(fp);
}
void main()
{
read();
getch();
}