我寫了簡單C shell的退出部分。條件比較
int main(int argc, char*argv[]){
while(1){
char input_line[MAX], *tokens[X_MAX];
int i,n; //n is the number of tokens inside the *tokens
.
.
.//gets the input from user and stores into tokens
.
if(n ==1){
char *ex = "exit";
printf("difference: %i\n",strcmp(tokens[0],ex)); //this prints out 10
}
}
}
當他們不同時,我被卡在部分,當他們顯然他們不是。我想要做的是,當用戶輸入「exit」(存儲在char數組中的「標記」)時,if語句將其選中,然後將其與「ex」中存儲的語句進行比較。
有什麼想法?
感謝
檢查輸入中是否有多餘的空白。 –