我需要将数组聊天值数组放入指针数组中。首先,我使用了这样的代码,它对我有用。
char *current_tag_lists[20];
char current_tag_list1[]="0005808897";
char current_tag_list2[]="0009953997";
char current_tag_list3[]="0000116600";
current_tag_lists[0] = current_tag_list1;
current_tag_lists[1] = current_tag_list2;
current_tag_lists[2] = current_tag_list3;
所以我可以通过 index 访问该值current_tag_lists[0]
。
但我的实际要求是在运行时添加这些值,如下所示。这是一个示例代码。
char *current_tag_lists[20];
while(k<6)
{
char RFID_input_characters[12];
while(a<13){
if(a==12){
current_tag_lists[k]=RFID_input_characters;
a=0;
k++;
break;
}
else{
RFID_input_characters[a]='a'; // this example in my code it get value like this
a++;
}
}
}
但问题是“current_tag_lists”不存储所有值。它只存储当前值。它每次都替换以前的值。我需要将值保留为我上面的示例,并且需要从索引(current_tag_lists [0])访问。
谁能帮帮我吗。这是我的实际代码。
while(k<6)//while(!(c1==1))
{
char RFID_input_characters[12]={0};
while(a<14){
if (a == 0) {
ReceiveByteSerially();
a++;
}
else if (a == 13 ) {
ReceiveByteSerially();
current_tag_lists[k] = malloc(strlen(RFID_input_characters) + 1);
strcpy(current_tag_lists[k], RFID_input_characters);
Lcd_Set_Cursor(1,1);
Lcd_Write_String(RFID_input_characters);
Lcd_Set_Cursor(2,1);
Lcd_Write_String(current_tag_lists[k]);
a = 0;
k++;
break;
}
else if(k%2!=0 && a==1){
char x=ReceiveByteSerially();
if((x!=0x02)&&(x!=0X03)){
a++;
}
}
else{
char x=ReceiveByteSerially();
if((x!=0x02)&&(x!=0X03)){
if(k%2 !=0){
RFID_input_characters[a-2] = x;
}
else if(a<12){
RFID_input_characters[a-1] = x;
}
a++;
}
}
}
}
请只看 if(a==13)。
这是我的错误日志。
C:\Program Files (x86)\Microchip\xc8\v1.33\sources\common\strcpy.c:19: error: (1466) registers unavailable for code generation of this expression
(908) exit status = 1
make[2]: *** [dist/default/production/Super_Smart_Backpack.X.production.hex] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2`
`nbproject/Makefile-default.mk:119: recipe for target 'dist/default/production/Super_Smart_Backpack.X.production.hex' failed
make[2]: Leaving directory 'F:/Irushi-final/Super Smart Backpack.X/Super Smart Backpack.X'
nbproject/Makefile-default.mk:78: recipe for target '.build-conf' failed
make[1]: Leaving directory 'F:/Irushi-final/Super Smart Backpack.X/Super Smart Backpack.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
BUILD FAILED (exit value 2, total time: 1s)