求助一个问题。困扰我几天了。
#include <stdio.h>
#include <malloc.h>
#include <string.h>
typedef struct
{
int num;
float score;
struct *next;
}stu;
#define LEN sizeof(stu)
int main(void)
{
stu *p1;
p1=(stu*)malloc(LEN);
scanf("%d%f",&p1->num,&p1->score);
}
//这段代码运行后输入第二个值时就会出错。如下图
------解决思路----------------------typedef struct
{
int num;
float score;
struct
stu *next;
}stu;
试试这样呢
------解决思路----------------------我试了试一切正常呀,不过我用的VS2010不知道有没有关系。
------解决思路----------------------代码编译不过需要 修改为
typedef struct stu
{
int num;
float score;
struct stu *next;
}stu;
没发现有什么问题
------解决思路----------------------
有可能前面编译器抽了,重新build一下后就好了。
------解决思路----------------------楼主想做个学生类的链表吧。VC6有些地方做得不太好,毕竟有点老了。是不是要clean一下。
------解决思路----------------------崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处,看不懂时双击下一行,直到能看懂为止。
------解决思路----------------------拿VC6试了一下,确实如楼主所说
但在我的MinGW上直接编译报错,怀疑 struct *next; 这种写法只有VC支持,不过这应该不是问题所在
但是MinGW上编译通过后,运行没有任何错误,猜测还是VC6的问题
------解决思路----------------------typedef struct st
{
int num;
float score;
struct st *next;
}stu;
#define LEN sizeof(stu)
int _tmain(int argc, _TCHAR* argv[])
{
stu *p1;
p1=(stu*)malloc(LEN);
scanf("%d%f",&p1->num,&p1->score);
return 0;
}
这样再错就见鬼了, 你那样不报错就简直是。。。 struct * next; 这是啥