文件读写菜鸟问题求助
#include <stdio.h>#include <malloc.h>#include <string.h>int main(){ FILE *pFile = fopen("1.txt","w+"); fwrite("hello,world!",1,strlen("hello,world!"),pFile); fflush(pFile); fseek(pFile,0,SEEK_SET); //文件指针设为起点,写操作覆盖原来的内容 fwrite("欢迎访问",1,strlen("欢迎访问"),pFile); fseek(pFile,0,SEEK_END); //文件指针设为终点 int len = ftell(pFile); //获取文件字节数 char* ch = (char*)malloc(sizeof(char)* (len+1)); //分配内存,多一个字节 memset(ch,0,(len+1)); //清0 int num = fread(ch,1,len,pFile);//读取文件 printf("读出字节:%d\n",num); //为什么num为0?? fclose(pFile); printf("%s",ch); return 0;}