我正在尝试将一个字符串解析为更小的字符串,提取一些值,然后我想检查这些值中是否有任何一个是骗子......
这是我的蹩脚代码:)
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] ="INVITE sip:alice1@open-ims.test SIP/2.0\nCall-ID: mndfdnf8e4953t984egnue@open-ims.test To: <sip:alice2@open-ims.test>;<sip:alice@open-ims.test>;<sip:alice4@open-ims.test>;<sip:alice5@open-ims.test>;<sip:alice6@open-ims.test>;<sip:alice@open-ims.test>;<sip:alice8@open-ims.test>;<sip:alice9@open-ims.test>;<sip:alice10@open-ims.test>;<sip:alice11@open-ims.test>;<sip:alice12@open-ims.test>;";
char * tch;
char * saved;
char * array[50];
int count = 0;
tch = strtok (str,"<:;>");
while (tch != NULL)
{
int savenext = 0;
if (!strcmp(tch, "sip"))
{
savenext = 1;
}
printf ("%s\n",tch);
tch = strtok (NULL, "<:;>");
if (savenext == 1)
{
saved = tch;
}
if ( count == 0 ) {
array[count] = saved;
count ++;
}
if ( count > 0 ) {
int i = 0;
while (i < count ) {
if (array[count] == saved ) {
printf("FOUND!");
}
i++;}
}
}
}
我要做的是检查是否在字符串中找到了两次相同的用户名,但是我缺乏指针经验使我无法做到这一点。我无法弄清楚为什么这些值不会添加到数组中。
欢迎和赞赏任何帮助