哪位C语言高手帮忙看一下

来源:百度知道 编辑:UC知道 时间:2024/05/16 23:21:30
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct ONPLANE
{
int num;
struct ONPLANE *next;
}*on_queue;
struct on_linkqueue
{
on_queue front;
on_queue rear;
};
main()
{
on_linkqueue on;
on.front=on.rear=(on_queue)malloc(sizeof(ONPLANE));
on.front->next=NULL;
}
上面的程序到底错了哪里?

#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct ONPLANE
{
int num;
struct ONPLANE *next;
}*on_queue;
struct on_linkqueue
{
on_queue front;
on_queue rear;
};
main()
{
struct on_linkqueue on; /*这里添加一个struct*/
on.front=on.rear=(on_queue)malloc(sizeof(struct ONPLANE)); /*这里也要添加一个struct*/
on.front->next=NULL;
}

上面的程序在TC2.0中运行通过,C语言中结构体类型声明变量时必须是在前面加上struct
C++中可以直接用声明结构体类型变量不需要在类型前加struct,我试了一下,把你的程序保存在后缀为.cpp文件中在VC6.0中可以运行.