void verification() {
char pass[50];
printf(" Enter Password : ");
fgets(pass, 50, stdin);
if (pass != 'aaanc6400') { \\ Warning message in here
printf("\n Invalid Password.. Please enter the correct password. \n\n");
verification();
}
info();
}
當我編譯該程序,在標記行它示出警告「字符常數太長其類型」,也是「指針和整數之間的比較」。然後當我運行代碼並輸入正確的密碼時,它仍會打印密碼錯誤。我究竟做錯了什麼?字符常數太長其類型(與fgets)
@A。色調。是的,我試過了。然後出現另一個警告消息「比較字符串文字結果在未指定的行爲」 –
''aaanc6400''是一個多字節字符常量,這當然不是你想要的。您需要使用雙引號(用於c字符串)並使用strcmp()來比較它們。 –
@你只在單個字符上使用單引號,而不是在字符串上(儘管我想P.P.的解釋更好)。儘管對上述問題的回答解決了這個問題,但我並不認爲這是一個確切的發表。 – Lehue