【发布时间】:2013-09-14 13:20:30
【问题描述】:
我正在处理这段代码:
struct box
{
char word[200][200];
char meaning[200][200];
int count;
};
struct root {
box *alphabets[26];
};
root *stem;
box *access;
void init(){
//cout<<"start";
for(int i = 0 ; i<= 25; i++){
struct box *temp =(struct box*)( malloc(sizeof(struct box)*100));
temp->count = 0;
cout<<temp->count;
stem->alphabets[i] = temp;
}
//cout<<" initialized";
}
它编译时没有错误,但在执行过程中它会停在temp 分配给stem->alphabets[i] 的位置。如何解决这个问题?
【问题讨论】:
-
stem未初始化。从而崩溃。也初始化access。 -
您使用的是 C 还是 C++?它们是不同的语言。
-
你为什么在 C++ 程序中使用 malloc ???
-
选择一个 C 或 C++ ?使用 C++,您拥有 STL,让您的工作更轻松。
标签: c++ c pointers struct malloc