所以我在比较存储在LinkedList中的字符串时遇到问题。链接列表中的所有值都存储为Void *,但是我不太确定如何将void *与字符串进行比较。我试过使用strcmp(),但是没有运气。有人可以指出我正确的方向。谢谢。
LinkedList类:
typedef struct MissileNode
{
//It can store any data types
void* missile;
struct MissileNode* next;
}missile_node_t;
主类:
missile_node_t* current = missiles->head;
//This totally prints perfectly
printf("Current Missile: %s\n\n", current->missile);
//This is where I am having issue, my comparsion is not working
if(strcmp((char*)current->missile),"Single") == 0)
{
printf("work");
}
else
{
printf("doest work");
}
current = current-> next;
输出:
Current Missile: Single
doesn't work