我不明白爲什麼我的字符串比較沒有正確比較。這是C.字符串比較在C工作不正常
它從建立這樣的文件中讀取:
1 - ls
2 - cd
3 - history
如果我按c它想抓住以「C」開始上次使用的串並運行!命令。但它永遠不會進入if(strcmp(())= 0)行。我的代碼
部分是在這裏:
char currLine[MAXINPUTLINE];
else if (isalpha(input[1])){
int count = 1;
fileRead = fopen(".simpleshell_history", "r");
while(fscanf(fileRead, "%s\n", currLine) != EOF){
printf(input+1);
printf(currLine);
if(strcmp((input+1), currLine) == 0){
printf("%s\n", currLine);
parse(currLine);
}
}
}
這是在while循環打印的printf的,我不知道如何解決這個問題,我一直在堅持了一段時間。這是當我輸入'!c'
c
1c
-c
lsc
2c
-c
cdc
3c
-c
historyc
4c
-c
!c!c
你有沒有在輸出什麼? – klm123
你是什麼意思?現在假設進入if語句並輸出currLine,但它只循環while循環而不進入if語句。 – user2318083
你有printf -s那裏。他們打印什麼? – klm123