typedef struct
{
int A;
int B;
char* C; // problem is here
}foo;
int SetA(void)
{
....
return retval;
}
int SetB(void)
{
....
return retval;
}
const char* bar(void)
{
.....
char* retval="return val";
.....
return retval;
}
void SetFoo(foo* paramFoo)
{
paramFoo->A = SetA();
paramFoo->B = SetB();
paramFoo->C = bar();
}
static foo staticFoo;
void main()
{
SetFoo(&staticFoo);
printf("%s",staticFoo.C);// printing
}
一切都会正常,但struct foo中的“char * C”不会被正确写入。为什么?我需要知道我是否犯错,以及如何纠正它?我已经跑了吧(),它返回正确的值。指向结构成员的指针
谢谢 〜最大
请修复格式 – Matteo 2012-03-01 17:44:59
你是什么意思“写得不好”。你怎么知道 ? – cnicutar 2012-03-01 17:46:14
@cnicutar没有什么会被写入,当我尝试印刷它时,它不会给我任何东西。 – 2012-03-01 17:48:55