I need put array of array chat values in to pointer array. for that first I used code like this and it works for me.
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;
so I can access the value by index current_tag_lists[0]
.
But my actual requirement is to add these value in run time as follows. This is a example code.
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++;
}
}
}
But the problem is that "current_tag_lists" does not store all the values. it only store the current value. It every time replace the previous value. i need to keep the values as my above example and need to access from index (current_tag_lists[0]).
Can anyone please help me. This is my actual code.
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++;
}
}
}
}
please only look the if(a==13).
This is my error log.
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)
This is how you can do it:
If I got you correctly.
don't forget to
free
later.The way you had it always you were setting each pointer point to the same address - that is starting address of array
RFID_input_characters
(the assignment you had there was not copying the string, just setting k-th pointer point to the start ofRFID_input_characters
array. To copy strings you can usestrcpy
or its safer versions for instance).