#include <stdio.h>
int main(int argc,char *argv[])
{
FILE *fp;
char writeBuff[]="hello world";
char readBuff[128]={0};
fp = fopen("a.c","w+");
if(fp==NULL)
{
printf("open file failed\n");
return -1;
}
fputs(writeBuff,fp);//写
fseek(fp,0,SEEK_SET);//不加这行找不到a.c文件的内容从哪里开始,最终导致打印只有readBuff is
fgets(readBuff,128,fp);//读
printf("readBuff is %s\n",readBuff);
fclose(fp);
return 0;
}
fseek(fp,0,SEEK_SET);///光标移动到文件头部
int feof(FILE *stream);
功能:判断是否已经到文件结束
参数:文件流
返回值:到文件结束,返回为非0,没有则返回0
int ferror(FILE *stream);
功能:判断是否读写错误
参数:文件流
返回值:是读写错误,返回为非0,不是则返回0
void clearerr(FILE *stream);
功能:清除流错误
参数:文件流