...
main() {
char **src_ip[10];
char **dest_ip[10];
char **lat[10];
char *ip[20];
while{
//Read file
//fgets();
src_ip[j] = &data[0];
dest_ip[j] = &data[1];
lat[j] = &data[2];
int idx;
int addip;
for(idx=0; idx<20; idx++)
{
addip = 0;
//Check to see if the IP address is already in the array.
if ((strcmp(*(src_ip[j]), ip[idx]) == 0) ||
(strcmp(*(dest_ip[j]), ip[idx]) == 0))
{
addip=1;
break;
}
//If the IP address was already found then addip would equal 1.
if (!addip){
printf("new node: %s",*(ip[idx]));
}
else
printf("Exist");
}
}
j++;
}
我想比较两个一维数组中的字符字符串 - 数组src_ip[j]
和dest_ip[j]
- 并插入到一个数组 ip[idx] 中。例如,当我查找 时ip[1]
,它会转到src_ip[1]
,这意味着它只引用一个数组 - ip[idx]
- 而不是单独查找src_ip
and dest_ip
。
代码中一定有问题 - 也许我遗漏了一些东西?