#include<stdio.h>
int main()
{
//使用fputc函数写文件,并学习文件打开关闭方式
FILE *fp;
char ch;
if((fp=fopen("exp01.txt","w"))==NULL)
{
printf("can not open file.\n");
//exit(0);
return 0;
}
ch = getchar();
while(ch!='#')
{
fputc(ch,fp);
ch = getchar();
}
fclose(fp);
//使用fgetc读取文件内容
if((fp=fopen("exp01.txt","r"))==NULL)
{
fprintf(stdout,"can not open file.\n",0);
getchar();
return 0;
}
ch = fgetc(fp);
char *chf;
while(ch!=EOF)
{
chf=&ch;
if(ch!='\n') //'\r'回车,'\n'回车换行,可以做为判断
{
printf("%c ",ch);
fprintf(stdout,"%c ",ch);
}
fprintf(stdout,"address is %ld\n",chf);
ch = fgetc(fp);
//break;
}
fprintf(stdout,"hammer",2);
return 0;
}