我正在編寫一個程序來檢測網絡釣魚。我試圖檢查URL的基礎,如果它在標籤中是否相同。 例如在http://maps.google.com「> www.maps.yahoo.com 我試圖檢查URL的最後2部分是否相同,即如果google.com = yahoo.com或不。比較兩個指針指向
我用下面的代碼可以這樣做:
void checkBase(char *add1, char *add2){
char *base1[100], *base2[100];
int count1 = 0, count2 = 0;
base1[count1] = strtok(add1, ".");
while(base1[count1] != NULL){
count1++;
base1[count1] = strtok(NULL, ".");
}
base2[count2] = strtok(add2, ".");
while(base2[count2] != NULL){
count2++;
base2[count2] = strtok(NULL, ".");
}
if((base1[count1-1] != base2[count2-1]) && (base1[count1-2] != base2[count2-2])){
cout << "Bases do not match: " << endl
<< base1[count1-2] << "." << base1[count1-1] << " and "
<< base2[count2-2] << "." << base2[count2-1] << endl;
}
else{
cout << "Bases match: " << endl
<< base1[count1-2] << "." << base1[count1-1] << " and "
<< base2[count2-2] << "." << base2[count2-1] << endl;
}
}
我不知道如果我在if語句是正確的比較或不是我傳遞兩個網址。 感謝
不是本有庫? – chris
可能重複[什麼是比較兩個C風格字符串的正確功能?](http://stackoverflow.com/questions/9122000/what-is-the-proper-function-for-comparing-two-c-風格字符串) – jogojapan