注册 登录
编程论坛 C++教室

大家帮我看看啊 死循环 很奇怪

精灵传说 发布于 2008-05-19 15:04, 742 次点击
请各位高手帮帮忙啊 我参考教程做的 可是形成死循环 麻烦大家忙我找找错在哪 谢谢先
是一个成绩保存系统 问题可能是在链表的创建上
first = new Student[num];
for(int i=1 ; i<num ; i++)
{
        point->next = first + i;
        point = point->next;
}
        point->next=NULL;
对了 再弱弱问一下 象这样的系统 该怎么样保存输入的数据呢
原代码如下
struct Student
{
    int   number;
    char  name[20];
    int   chinese;
    int   english;
    Student *next;
};

class Score
{
public:
    Score(int num)
    {
        first = new Student[num];
        point = first;
        for(int i=1 ; i<num ; i++)
        {
            point->number  = i;
            strcpy(point->name,"null");
            point->chinese = 0;
            point->english = 0;
            point->next = first + i;
            point = point->next;
        }
            point->number  = num;
            strcpy(point->name,"null");
            point->chinese = 0;
            point->english = 0;
            point->next    = NULL;
    }


    void Creat();
    void Show();

protected:
    Student *first;
    Student *point;
};

[[it] 本帖最后由 精灵传说 于 2008-5-19 16:38 编辑 [/it]]
3 回复
#2
wfx_best2008-05-19 15:21
能不能详细说明你遇到的困难,而不是发整个代码给人家读.
#3
p1s2008-05-19 19:04
貌似LZ的写法是申请了堆内存数组,而不是链表啊。链表么是一个一个节点申请的啊!
first = new Student[num];//这个是数组阿
#4
dubaoshi2008-05-20 10:31
代码还真看不懂,能发一下完整代码不?
另外如果要保存数据的话,应该加上头文件:fstream
1