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;
}
原文地址:https://www.cnblogs.com/wangjixianyun/p/2983655.html