如何将两个数组包含在第三个数组中通过指针分别调用
大概意思是将两个不同的数组a[],b[]包含在第三个数组c[]中,c[0]指的就是a数组,c[1]指的就是b数。
比如a[]={12,2,5,4};那么c[0].a[0]=12;
源码实例
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
#include<fcntl.h>
#define u8 unsigned char
typedef struct
{
u8 KeyCurrentIndex;//当前状态索引号
u8 KeyEnterState;//按下【enter】键时转向的索引号
u8 KeyCancelState;//按下【cancel】键时转向的索引号
u8 KeyUpState;//按下【up】键时转向的索引号
u8 KeyDownState;//按下【down】键时转向的索引号
void (*CurrentOperate)(); //当前状态下执行的功能操作
}KbdTabStruct;
const KbdTabStruct GTA_KeyTab[]=
{
{0,1,2,3,4,},//待机界面
{1,0,0,0,0,},
{2,0,0,0,0,},
{3,0,0,0,0,},
{4,0,0,0,20,},
{0,1,2,3,4,},//待机界面
{1,0,0,0,0,},
{2,0,0,0,0,},
{3,0,0,0,0,},
{4,0,0,0,20,},
};
const KbdTabStruct KeyTab[]=
{
{0,1,2,3,4,},//待机界面
{1,0,0,0,0,},
{2,0,0,0,0,},
{3,0,0,0,0,},
{4,0,0,0,0,},
{4,0,0,0,0,},
{3,0,0,0,0,},
{4,0,0,0,0,},
{4,0,0,0,0,},
};
int main()
{
const KbdTabStruct KBD[]=
{
{0,1,2,3,4,(*main)},
{6,7,8,9,10,11},
{0,1,2,3,4,5},
{0,1,2,3,4,5},
};
const KbdTabStruct KBD1=
{
20,27,38,39,40,51,
};
typedef struct
{
const KbdTabStruct *KTab;
}MENUSW,*menu_sw;
const MENUSW MENU_TABLE[]={GTA_KeyTab,KeyTab};
KbdTabStruct *ptr=&KBD[1];//定义指向结构体的指针变量 ptr 并赋初值KBD
KbdTabStruct *pr=&KBD1;//定义指向结构体的指针变量 pr 赋初值KBD1
printf("%d\r\n",KBD[0].KeyEnterState);//应是1
printf("%d\r\n",KBD[1].KeyCurrentIndex);//6
printf("%d\r\n",KBD[1].KeyDownState);//10
printf("%d\r\n",ptr->KeyDownState);//10
printf("%d\r\n",(*ptr).KeyDownState);//10
printf("%d\r\n",(*pr).KeyDownState);//40
printf("%d\r\n",MENU_TABLE[0].KTab[8].KeyDownState);//20
printf("%d\r\n",MENU_TABLE[0].KTab[4].KeyDownState);//20
}