我有2個字符數組:比較十六進制字符陣列
unsigned char test_1[2] and unsigned char test_2[2]
它們兩者在它的十六進制值。所以,如果我像循環do:
for (i=0; i<sizeof(test_1); i++)
printf("%02x\n", test_1[i])
and
for (i=0; i<sizeof(test_2); i++)
printf("%02x\n", test_2[i])
它會打印出類似這樣:
2e
50
and
a1
3e
我的問題是,我該如何比較這兩個字符數組?我有許多字符數組,如test_3, test_4, ...., test_n
與test_1
進行比較。
我用strcmp()
,它失敗了,因爲它們不是一個字符串。
******更新*******
代碼邏輯:
while(memcmp(test_1, test_n,2) != 0){
// grab the next test_n char array (test_2, test_3, ....)
// set test_n to have same value as the next test_n
}
printf("Stop the search, I found it!"\n);
看看'memcmp()'。 – chux
@chux它沒有工作。我嘗試了它,並沒有停止在'test_5'。我有意用'test_1'填充'test_5'。 – ThomasWest
「它沒有工作」不是一個明確的解釋,什麼試過,結果與預期的結果。 – chux