c 指针作为出参

复制代码
int load(char * filaName , char *& buffer){
    
    FILE *file;

    if((file = fopen("D://a.txt","r")) == NULL)
    {
        printf("cant open file!");
    }
    fseek (file, 0, SEEK_END);   // non-portable
    char *c = "";
    int size=ftell (file);
    rewind (file);
    buffer = new char[size+1];
    *(buffer+size) = 0;
    int result = fread(buffer,sizeof(char),size,file);

    if(fclose(file)) printf("file close error!");
    return size;
}
复制代码

调用

int _tmain(int argc, _TCHAR* argv[])
{
    char *str;
    int size = load("",str);
    printf("%s",str);
    scanf("sad");
    return 0;
}

 

posted @   fff8965  阅读(425)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示