C程序有什么问题,怎么打印不出结果。

[复制链接]
查看11 | 回复2 | 2011-5-31 14:08:29 | 显示全部楼层 |阅读模式
#include "stdafx.h"
#include "string.h"
#include "malloc.h"
char * getmemory(char * p)
{

        p=(char *)malloc(100);

        strcpy(p,"hello world");
}
int main(int argc, char* argv[])
{
        char * str=NULL;
        getmemory(str);
        printf("%s\n",str);
        free(str);
        return 0;
}

回复

使用道具 举报

千问 | 2011-5-31 14:08:29 | 显示全部楼层
#include "stdio.h"#include "string.h"#include "malloc.h"char * getmemory(char * p){
p=(char *)malloc(100);
strcpy(p,"hello world");return p;} int main(int argc, char* argv[]){char * str=NULL;str = getmemory(str); printf("%s\n",str);free(str);return 0;}...
回复

使用道具 举报

千问 | 2011-5-31 14:08:29 | 显示全部楼层
你如果不return 的话就需要传入指针的指针...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行