I have a requirement where I have to get the RFID RSSI value which is an int and convert it to a char pointer and append to it. Below is how I did it.
char *epcBytes = (char *)tag_operation_report->tag.epc.bytes;
int rssiString = fabs(tag_operation_report->tag.rssi);
char *rssiVal = (char *)rssiString;
char* rssi = "rssi";
char *rssiResult = malloc(strlen(&rssi) + strlen(&rssiVal) + 1);
strcpy(rssiResult, &rssi);
strcpy(rssiResult + strlen(&rssi), &rssiVal);
char *result = malloc(strlen(&epcBytes) + strlen(&rssiResult) + 1);
strcpy(result, &epcBytes);
strcpy(result + strlen(&epcBytes), &rssiResult);
data = (void*)result;
But I am getting the following exception while I run the code.
Unhandled exception at 0x00007FFBD017B2E5 (msvcr120d.dll) in RFIDTest.exe: 0xC0000005: Access violation writing location 0x0000000000000000.
What am I doing wrong here? When I run this on an online C compiler, it runs fine. This exception is thrown at the line,
strcpy(rssiResult, &rssi);