int wr_ret;
int rd_ret;
FILE *fp;
unsigned long file_size;
//char wr_buf[100] = "hello world";
char rd_buf[100];
fp = fopen("ip.txt", "a+");//可读可写文件不存在则创建
if (fp == NULL)
{
perror("open file error:");//根据error输出错误信息
return -1;
}
wr_ret = fwrite(wr_buf, sizeof(wr_buf), 1, fp);
printf("wr_ret = %d\n", wr_ret);
rewind(fp);//将文件偏移到文件开始位置
rd_ret = fread(rd_buf, sizeof(rd_buf), 1, fp);
printf("rd_ret = %d\n", rd_ret);
printf("content=%s\n", rd_buf);
fseek(fp, 0, SEEK_END);
file_size = ftell(fp);
printf("file_size = %lu\n", file_size);
fclose(fp);//关闭
return 1;