指针问题,求各位帮忙,这个程序怎么改?
#include<stdio.h>#include<stdlib.h>
#include<string.h>
void GetMemory(char *p)
{
p={char *)malloc(100);
}
{
char*str=NULL;
GetMemory(str);
stcpy(str,"hello word");
printf("%s\n",str);
return 0;
}
2016-05-19 16:58
新手,求帮忙
2016-05-19 16:59
程序代码:#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char* GetMemory()
{
return (char *)malloc(100);
}
int main()
{
char*str = GetMemory();
//GetMemory(str);
strcpy(str, "hello word");
printf("%s\n", str);
return 0;
}
2016-05-19 17:05
程序代码:#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void GetMemory(char **p)
{
*p = (char *)malloc(100);
}
int main()
{
char*str = NULL;
GetMemory(&str);
strcpy(str, "hello word");
printf("%s\n", str);
return 0;
}
2016-05-19 17:06