所以下面是我在 c 中的源代碼,其中我使用 strcmp 函式來比較兩個字串
#include<stdio.h>
#include<string.h>
int main() {
unsigned char pass[100]="Try to hack me";
unsigned char input[100];
printf("Enter the secret string: ");
scanf("%s",input);
if(strcmp(pass,input))
printf("Wrong Password\nAccess Denied\n");
else
printf("Right password\nAccess Granted!!\n");
return 0;
}
當我運行編譯的程式時,它給出了錯誤的輸出,它假設給出了正確的訊息,但它給出了錯誤的訊息。這里有什么問題?
下面是程式的輸出回應
professor@CTOS:~/Documents/Bnry/elf32bit/Module3/ch6$ ./crackme
Enter the secret string: Try to hack me
Wrong Password
Access Denied
professor@CTOS:~/Documents/Bnry/elf32bit/Module3/ch6$ ./crackme
Enter the secret string: Try to hack me
Wrong Password
Access Denied
uj5u.com熱心網友回復:
%sinscanf只讀取到一個空格字符。從“Try to hack me”開始,它只顯示“Try”。可能使用不同的方法來讀取輸入行,fgets但請注意其中fgets包含終止該行的換行符。
當你的程式不作業時,除錯它。使用除錯器跟蹤執行或插入printf陳述句以顯示它在做什么。printf("The input is %s.\n", input);在之后插入scanf會發現問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/505645.html
上一篇:如何解決Boost錯誤:在拋出'boost::interprocess::interprocess_exception'的實體后呼叫終止
