gpt4 book ai didi

c - Keil中结构体链表错误

转载 作者:行者123 更新时间:2023-11-30 14:54:26 25 4
gpt4 key购买 nike

我正在开发我的一个项目,下面发布的代码在 Dev C 中成功运行,并带有 O/P。然而 Keil 吐出了一些错误,不幸的是我无法确定这些错误。

一些示例:

8051TEST.C(322): warning C198: sizeof returns zero

8051TEST.C(324): error C230: 'switc': unknown struct/union/enum tag

8051TEST.C(324): error C204: 's0': undefined member

8051TEST.C(325): error C230: 'switc': unknown struct/union/enum tag

8051TEST.C(325): error C204: 's1': undefined member

8051TEST.C(326): error C230: 'switc': unknown struct/union/enum tag

真的很想要一双新鲜的眼睛。

谢谢,奥勒留

 typedef struct
{
int s0;
int s1;
int s2;
int s3;
int c;
int name_len;
int struct_size;
char sw_name[10]; //variable length array must be last.
}switc;

//Memory allocation and initialisation of structure
struct switc *createsw(struct switc *s, int id1, int id2, int id3, int id4,
int id5, char a[])
{
s = malloc( sizeof(*s) + sizeof(char) * strlen(a) );

s->s0 = id1;
s->s1 = id2;
s->s2 = id3;
s->s3 = id4;
s->c = id5;
s->name_len = strlen(a);
strcpy(s->sw_name, a);

s->struct_size = ( sizeof(*s) + sizeof(char) * strlen(s->sw_name) );

return s;
}

struct newcard //create your own configuration
{
int pos_sw1;
int pos_sw2;
int pos_sw3;
int pos_sw4;
int pos_sw5;
int pos_sw6;
int pos_sw7;
};

struct newcard *createcard(struct newcard *c, int sr1, int sr2, int sr3,
int sr4, int sr5, int sr6, int sr7)
{
c = malloc( sizeof(*c));

c->pos_sw1 = sr1;
c->pos_sw2 = sr2;
c->pos_sw3 = sr3;
c->pos_sw4 = sr4;
c->pos_sw5 = sr5;
c->pos_sw6 = sr6;
c->pos_sw7 = sr7;
return c;
}

我的 int main() 按要求。有点大杂烩所以提前道歉。整个事情在 Dev C 中完美运行。

  int main()
{
Lcd4_Init();
Lcd4_Clear();
switc *s1, *s2, *s3, *s4, *s5, *s6 , *s7;
int id1[5],id2[5],id3[5],id4[5],id5[5],id6[5],id7[5],pos=3;
int cd1[7],cd2[7],cd3[7],cd4[7],cd5[7],cd6[7],sw1=0,sw2=0,sw3=0,sw4=0,sw5=0,
sw6=0,s
w7=0,card=0,menu=0,n=7;
int *cd7=(int *)malloc(n * sizeof(int));

M:menu=main_menu();

if(menu==1)//menu to monitor functions
{
confsel();
goto M;
}

//assign number to card based on option selected.
if(menu==2){
card=cardsel();
}

if(menu==3)//Mini info guide
{
printf("\nPCB for 6x8 through(SW 1,2,3,4,5,7) + 1x11 through(SW 6) ROTARY SWITCH(s).\n");
printf("\nSwitch LAYER(s) by 1:8 and 1:16 DEMUX.\n");
printf("\nTRIGGER to DEMUX(s) by 8255A-5 PPI.\n");
printf("\nAT89C51RD2 powering device.\n");
printf("\nEnter card when PROMPTED.\n");
printf("\nCOOLING FAN provided.\n");
printf("\nPOTENTIOMETER P(1-5) must be ANTI-CLOCKWISE.\n");
goto M;
}

switch(card)
{
case 1:
printf("Power Card assigned\n");
memcpy(cd1,&pcard,sizeof(cd1));
sw1=cd1[0];
sw2=cd1[1];
sw3=cd1[2];
sw4=cd1[3];
sw5=cd1[4];
sw6=cd1[5];
sw7=cd1[6];
break;
case 2:
printf("Firing Card assigned\n");
memcpy(cd2,&fcard,sizeof(cd2));
sw1=cd2[0];
sw2=cd2[1];
sw3=cd2[2];
sw4=cd2[3];
sw5=cd2[4];
sw6=cd2[5];
sw7=cd2[6];
break;
case 3:
printf("Const. Curr. Card assigned\n");
memcpy(cd3,&c1card,sizeof(cd3));
sw1=cd3[0];
sw2=cd3[1];
sw3=cd3[2];
sw4=cd3[3];
sw5=cd3[4];
sw6=cd3[5];
sw7=cd3[6];
break;
case 4:
printf("Const. Curr. 2 Card assigned\n");
memcpy(cd4,&c2card,sizeof(cd4));
sw1=cd4[0];
sw2=cd4[1];
sw3=cd4[2];
sw4=cd4[3];
sw5=cd4[4];
sw6=cd4[5];
sw7=cd4[6];
break;
case 5:
printf("Amplifier Card assigned\n");
memcpy(cd5,&acard,sizeof(cd5));
sw1=cd5[0];
sw2=cd5[1];
sw3=cd5[2];
sw4=cd5[3];
sw5=cd5[4];
sw6=cd5[5];
sw7=cd5[6];
break;
case 6:
printf("NC (ATM) Card assigned\n");
memcpy(cd6,&nccard,sizeof(cd6));
sw1=cd6[0];
sw2=cd6[1];
sw3=cd6[2];
sw4=cd6[3];
sw5=cd6[4];
sw6=cd6[5];
sw7=cd6[6];
break;
case 7:
printf("Custom Card assigned\n");
incdec(cd7,n);//function to extract values to cd7[]
struct newcard *c1;
c1=createcard(c1,*(cd7 + 0),*(cd7 + 1),*(cd7 + 2),*(cd7 + 3),*(cd7 + 4),*(cd7 + 5),*(cd7 + 6));
sw1=c1->pos_sw1;
sw2=c1->pos_sw2;
sw3=c1->pos_sw3;
sw4=c1->pos_sw4;
sw5=c1->pos_sw5;
sw6=c1->pos_sw6;
sw7=c1->pos_sw7;
break;
default:
printf("Invalid Card assigned\n");
break;
}

按需菜单子(monad)例程。​​

   int main_menu()
{
const char Main_Menu [3][11] =
{
"1.CONFIG",//TBD
"2.LOAD",//load PRELOADED_CARD or create CUSTOM_CARD
"3.INFO"//check temp/voltage/credits
};
int menu=0,j=0,i=0;
Lcd4_Set_Cursor(1,3);
M:Lcd4_Write_String("Select your option:");
Lcd4_Set_Cursor(2,4);
Lcd4_Write_String(Main_Menu[j]);

do{
if(RK==0&&j<3)//Right Key
{
j++;
if(j>=0||j<3)
{
Lcd4_Set_Cursor(2,4);
Lcd4_Write_String(Main_Menu[j]);
}
}

if(LK==0&&j>0)//Left Key
{
j--;
if(j>=0||j<3)
{
Lcd4_Set_Cursor(2,4);
Lcd4_Write_String(Main_Menu[j]);
}
}

if(UK==0)//Up Key
{
goto M;
}

if(EK==0)//Enter Key
{
if(j>=0||j<3)
{
menu=j+1;
i=1;
}
}

return menu;
}while(i!=1);
}

按需提供错误消息(一旦 int main 启动,一切都会走下坡路。)

8051TEST.C(464):错误 C141:“switc”附近的语法错误

8051TEST.C(464):错误 C202:“s1”:未定义标识符

8051TEST.C(465): 错误 C141: 'int' 附近的语法错误

8051TEST.C(465):错误 C202:“id1”:未定义标识符

8051TEST.C(466): 错误 C141: 'int' 附近的语法错误

8051TEST.C(466):错误 C202:“cd1”:未定义标识符

8051TEST.C(467): 错误 C141: 'int' 附近的语法错误

8051TEST.C(467):错误 C202:“cd7”:未定义标识符

8051TEST.C(469):错误 C202:“菜单”:未定义标识符

8051TEST.C(471):错误 C202:“菜单”:未定义标识符

8051TEST.C(478):错误 C202:“菜单”:未定义标识符

还有 200 多个 C202。

最佳答案

当你typedef一个结构时,你只需要名称switch,所以要么不要typedef它,要么不要使用struct swift对于变量/参数。

关于c - Keil中结构体链表错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46729904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com