读取文件中的内容

 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

posted @ 2013-05-10 12:30  小小亮FLY  阅读(177)  评论(0编辑  收藏  举报