Hi good day. I tried to use your library to implement my linked list, here's the code that I made:
#include <LinkedList.h>
uint8_t buf[16] = {255, 200, 0x03, 0x84, 0x05, 0x06, 0x07, 0x08, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00};
class IP
{
public:
char *name;
};
char *string, *stringA, *temp;
LinkedList<IP *> myList = LinkedList<IP *>();
void setup()
{
delay(1000);
Serial.begin(9600);
string = (char *)malloc(sizeof(char *)*1024);
stringA = (char *)malloc(sizeof(char *)*1024);
temp = (char *)malloc(sizeof(char *)*1024);
}
void loop()
{
int cnt = 0;
char a[256];
for(int x = 0; x < sizeof(buf); x++)
{
cnt++;
sprintf(a, "%02X", (uint8_t)buf[x]);
strcat(stringA, a);
if(cnt%4 == 0)
{
if(strcmp(stringA, "00000000") != 0)
{
strcat(string, stringA);
}
strcpy(stringA, "");
}
buf[x] += 1;
}
int len = strlen(string);
while(len > 0)
{
snprintf(temp, 9, "%s", string+len-8);
strcat(stringA, temp);
if(len > 8)
{
strcat(stringA, "-");
}
len -= 8;
}
IP *ip = new IP();
ip->name = stringA;
myList.add(ip);
IP *route;
Serial.print("Size: ");
Serial.println(myList.size());
for(int f = 0; f < myList.size(); f++)
{
route = myList.get(f);
Serial.println(route->name);
}
strcpy(string, "");
strcpy(stringA, "");
strcpy(temp, "");
delay(1000);
}
I'm expecting my output to be:
Size: 1
00002000-00030000-05060708-FFC80384
Size: 2
00002000-00030000-05060708-FFC80384
01012101-01040101-06070809-00C90485
Size: 3
00002000-00030000-05060708-FFC80384
01012101-01040101-06070809-00C90485
02022202-02050202-0708090A-01CA0586
Size: 4
00002000-00030000-05060708-FFC80384
01012101-01040101-06070809-00C90485
02022202-02050202-0708090A-01CA0586
03032303-03060303-08090A0B-02CB0687
Size: 5
00002000-00030000-05060708-FFC80384
01012101-01040101-06070809-00C90485
02022202-02050202-0708090A-01CA0586
03032303-03060303-08090A0B-02CB0687
04042404-04070404-090A0B0C-03CC0788
Size: 6
00002000-00030000-05060708-FFC80384
01012101-01040101-06070809-00C90485
02022202-02050202-0708090A-01CA0586
03032303-03060303-08090A0B-02CB0687
04042404-04070404-090A0B0C-03CC0788
05052505-05080505-0A0B0C0D-04CD0889
Size: 7
00002000-00030000-05060708-FFC80384
01012101-01040101-06070809-00C90485
02022202-02050202-0708090A-01CA0586
03032303-03060303-08090A0B-02CB0687
04042404-04070404-090A0B0C-03CC0788
05052505-05080505-0A0B0C0D-04CD0889
06062606-06090606-0B0C0D0E-05CE098A
however, i got
Size: 1
00002000-00030000-05060708-FFC80384
Size: 2
01012101-01040101-06070809-00C90485
01012101-01040101-06070809-00C90485
Size: 3
02022202-02050202-0708090A-01CA0586
02022202-02050202-0708090A-01CA0586
02022202-02050202-0708090A-01CA0586
Size: 4
03032303-03060303-08090A0B-02CB0687
03032303-03060303-08090A0B-02CB0687
03032303-03060303-08090A0B-02CB0687
03032303-03060303-08090A0B-02CB0687
Size: 5
04042404-04070404-090A0B0C-03CC0788
04042404-04070404-090A0B0C-03CC0788
04042404-04070404-090A0B0C-03CC0788
04042404-04070404-090A0B0C-03CC0788
04042404-04070404-090A0B0C-03CC0788
Size: 6
05052505-05080505-0A0B0C0D-04CD0889
05052505-05080505-0A0B0C0D-04CD0889
05052505-05080505-0A0B0C0D-04CD0889
05052505-05080505-0A0B0C0D-04CD0889
05052505-05080505-0A0B0C0D-04CD0889
05052505-05080505-0A0B0C0D-04CD0889
Size: 7
06062606-06090606-0B0C0D0E-05CE098A
06062606-06090606-0B0C0D0E-05CE098A
06062606-06090606-0B0C0D0E-05CE098A
06062606-06090606-0B0C0D0E-05CE098A
06062606-06090606-0B0C0D0E-05CE098A
06062606-06090606-0B0C0D0E-05CE098A
06062606-06090606-0B0C0D0E-05CE098A
I'm wondering what could be the problem.
Thanks.