我想比較兩個char數組。但是,DoSomething()函數永遠不會被調用。我無法弄清楚爲什麼。這個C庫函數的用法有什麼問題?
我在做什麼錯?
//The value the user types in will be stored here:
char TempStorage[]={0,0,0,0,0,0};
//User types in a sequence here:
GetInput();
//One of the sequences that TempStorage will be compared to.
char Sequence[]={1,2,3,4,0,0};
//If the user typed in "123400" then DoSomething().
if(memcmp(TempStorage, Sequence, sizeof(TempStorage) == 0))
{
DoSomething();
}
同比可能要初始化序列這種方式'char Sequence [] = {'1','2','3','4',0,0};' – manuell
GetInput()函數是做什麼的?也許它會爲你的'TempStorage'指定ascii數字。也許它有另一個bug。 – nos