假設我具有類似於此的一段代碼擋土牆C內存:整個函數
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
我怎樣才能使信息 - >微型[0] - >名稱值應用於整個功能?
這非常混亂。給一些適當的代碼。 – slashmais 2010-10-27 07:05:13
當看到'malloc(sizeof(char *)* n)'時,別人的鐘聲響了嗎? – 2010-10-27 07:08:19