zoukankan      html  css  js  c++  java
  • C语言实现读取文件所有内容到字符串

    #include "stdio.h"
    #include "string"
    #include "stdlib.h"
    
    using namespace std;
    
    
    int main( void )
    {
        FILE *fp;
        fp = fopen("05.爱,九把刀系列之那些年,我们一起追的女孩.txt" , "r");
        fseek( fp , 0 , SEEK_END );
        int file_size;
        file_size = ftell( fp );
        printf( "%d" , file_size );
        char *tmp;
        fseek( fp , 0 , SEEK_SET);
        tmp =  (char *)malloc( file_size * sizeof( char ) );
        fread( tmp , file_size , sizeof(char) , fp);//个人觉得第三个参数不对
        printf("%s" , tmp );
        return 0;
    }

    摘自http://www.oschina.net/code/snippet_166355_9332#14930

  • 相关阅读:
    adjacent_diffenerce
    数值算法速食食谱
    accumulate
    平面分割
    进制转换
    奖学金
    谁考了第k名
    奇数单增序列
    病人排序
    灯的开关状态
  • 原文地址:https://www.cnblogs.com/starf/p/3658571.html
Copyright © 2011-2022 走看看