结构体中的成员**p怎么分配空间?
typedef struct{char **p32;
}LCM_STR;
lcm_str = (LCM_STR *)malloc(sizeof(LCM_STR));
lcm_str->p32 = (char **)malloc(50);
lcm_str->*p32 = (char *)malloc(50);
\main.cpp(322) : error C2065: 'p32' : undeclared identifier
\main.cpp(322) : error C2297: '->*' : illegal, right operand has type 'int' lcm_str->*p32的写法不行,试试*lcm_str->p32
另外指针本身只需要4字节就够,malloc(50)没必要吧 大多数情况下,sizeof(LCM_STR) =1 word = 32Bit 4字节吧 ,
指针4字节 , 指向指针的指针 也是4字节。 还不如用指针数组
char* p32;
p32 = (char*) malloc(50);
p32 = (char*) malloc(50);
strcpy(p32, "Hello");
strcpy(p32, "world"); jathenal 发表于 2012-10-8 13:11 static/image/common/back.gif
lcm_str->*p32的写法不行,试试*lcm_str->p32
另外指针本身只需要4字节就够,malloc(50)没必要吧 ...
*lcm_str->p32
可以用 谢谢!
页:
[1]