关于单片机语言c51和c语言的区别
在vc++6.0环境下编的树的结构程序在keil环境下却有错误。
如:
#include <string.h>
#include <iostream.h>
#include <stdio.h>
char MenuOne_Date[3][14]={ "1 Module Text ", "2 Tools ", "3 About Me "};
//这里和下面的MenuName[]改为unsigned 为什么有错?
char MenuTools_Date[4][11]={ "1 SetTime ", "2 Dingshi ", "3 MiaoBiao ", "4 Book "};
struct NodeDate
{
char seq;
char MenuName[17];
};
struct MenuNode
{
NodeDate data; ///这里keil uvision说是有错误的
struct MenuNode *parent;
struct MenuNode *firstchild;
struct MenuNode *nextbrd;
}*Previous,Module_Struct,Tools_Struct,AboutMe_Struct,SetTime_Struct,DingShi_Struct,MiaoBiao_Struct,Book_Struct;
void BuildNode(struct MenuNode * Self,struct MenuNode *Parent_Node,struct MenuNode *Firstchild_Node,
struct MenuNode *Nextbrd_Node,char seq,char MenuName[17])
{
Self-> parent=Parent_Node;
Self-> firstchild=Firstchild_Node;
Self-> nextbrd=Nextbrd_Node;
Self-> data.seq=seq;
strcpy(Self-> data.MenuName,MenuName);
}
void Initial_MenuStruct(void)
{
//第一层Menu
BuildNode(&Module_Struct,NULL,&SetTime_Struct,&Tools_Struct,10,MenuOne_Date[0]);
BuildNode(&Tools_Struct,NULL,NULL,&AboutMe_Struct,11,MenuOne_Date[1]);
BuildNode(&AboutMe_Struct,NULL,NULL,&Module_Struct,12,MenuOne_Date[2]);
Previous=&Module_Struct;
//Module子层Menu
BuildNode(&SetTime_Struct,&Module_Struct,NULL,&DingShi_Struct,20,MenuTools_Date[0]);
BuildNode(&DingShi_Struct,&Module_Struct,NULL,&MiaoBiao_Struct,21,MenuTools_Date[1]);
BuildNode(&MiaoBiao_Struct,&Module_Struct,NULL,&Book_Struct,22,MenuTools_Date[2]);
BuildNode(&Book_Struct,&Module_Struct,NULL,&SetTime_Struct,23,MenuTools_Date[3]);
}
void main(void)
{
Initial_MenuStruct();
for(int i=0;i <3;i++)
{
//cout < <Previous-> data.MenuName < < " " < <Previous-> data.seq < <endl;
printf( "%s\t%d\n ",Previous-> data.MenuName,Previous-> data.seq);
Previous=Previous-> nextbrd;
}
Previous=Module_Struct.firstchild;
for(i=0;i <4;i++)
{
printf( "%s\t%d\n ",Previous-> data.MenuName,Previous-> data.seq);
Previous=Previous-> nextbrd;
}
}
这个程序在vc是没问题的。
但在keil环境下 我删除了这里的main函数(我的工程在其他.c中是有main的),结构体没改,进行编译。出现错误:
struct MenuNode
{
NodeDate data;
struct MenuNode *parent;
struct MenuNode *firstchild;
struct MenuNode *nextbrd;
}
error 1: syntax error near 'NodeDate '
error 2: missing '; 'before 'data '
请问是什么原因啊 在线等待
[解决办法]
C,不是C++
如果不用typedef 就得用struct MenuNode.
struct MenuNode{
...
};//这里得有个分号