【发布时间】:2010-10-27 06:52:57
【问题描述】:
假设我有一段类似这样的代码:
SOMESTRUCTURE *info;
info = malloc(sizeof(SOMESTRUCTURE));
while(something...)
{
info->mini[0] = malloc(sizeof(SOMESTRUCTURE *)); // It's a structure inside the same structure
while(something...)
{
info->mini[x]->name = malloc(sizeof(char *)*strlen(name));
printf("%s\n", info->mini[0]->name); // This prints out the correct value
}
}
printf("%s\n", info->mini[0]->name); // But now the value is lost and is null
如何使 info->mini[0]->name 值适用于整个函数?
【问题讨论】:
-
这很乱。给出一些合适的代码。
-
看到这里的
malloc(sizeof(char *)*n),其他人的钟声不会响吗?
标签: c memory allocation