1 /**读取文本中的内容,返回值需要自己手动释放,utf8,unicode格式的文本读取后需要自己转换*/
 2 char* ReadFileContent(char *filePath, int &content_length)
 3 {
 4   FILE *fp = NULL;
 5   fopen_s(&fp, filePath, "rb");  
 6   assert(fp!=NULL);
 7   if (fp == NULL) return NULL;
 8 
 9   fseek(fp, 0, SEEK_END);
10   int isize = ftell(fp);
11   fseek(fp, 0, SEEK_SET);
12   char *buf = (char*)malloc(sizeof(char)*(isize+1));
13   assert(fp!=NULL);
14   memset(buf, 0, isize+1);
15 
16   content_length = fread(buf, 1, isize, fp);
17   fclose(fp);
18   return buf;
19 }

 文章出处:http://www.cnblogs.com/zhfuliang/archive/2013/05/10/3070915.html

相关文章:

  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2022-03-07
  • 2021-11-11
  • 2021-10-08
  • 2021-05-18
  • 2022-12-23
猜你喜欢
  • 2021-09-02
  • 2022-02-23
  • 2021-11-10
  • 2021-06-01
  • 2021-05-18
  • 2022-12-23
相关资源
相似解决方案