我该如何执行以下操作? full_agentstring需要指向cdr-> channel或cdr-> dstchannel:
....
char *cdr_channel = cdr->channel;
char *cdr_dstchannel = cdr->dstchannel;
char *full_agentstring = NULL;
if(strstr(cdr_channel, agent_pattern) != NULL) {
*full_agentstring = cdr->channel;
} else if(strstr(cdr_dstchannel, agent_pattern) != NULL) {
*full_agentstring = cdr->dstchannel;
我也试过full_agentstring = &cdr_dstchannel
但仍然收到警告:
从不兼容的指针类型[默认启用]
进行分配答案 0 :(得分:1)
if(strstr(cdr_channel, agent_pattern) != NULL) {
full_agentstring = cdr->channel;
} else if(strstr(cdr_dstchannel, agent_pattern) != NULL) {
full_agentstring = cdr->dstchannel;
或者,如果我不正确地理解你的问题,那么这是第二种方法
char *cdr_channel = cdr->channel;
char *cdr_dstchannel = cdr->dstchannel;
char **full_agentstring = NULL;
if(strstr(cdr_channel, agent_pattern) != NULL) {
full_agentstring = &cdr->channel;
} else if(strstr(cdr_dstchannel, agent_pattern) != NULL) {
full_agentstring = &cdr->dstchannel;