我写了一个比较字符串的简单应用程序。我的问题是空格。这是示例代码:
int main(int argc,char *argv[]) {
if(strcmp(argv[1], "go up")==0){
printf("up up and away\n");
}
if(strcmp(argv[1], "down")==0){
printf("down you go\n");
}
return 0;
}
现在用 gcc -o try try.c
编译后,我在我的终端中运行它:
./try go up // doesn't show anything
./try down //prints down you go
是否可以在 Linux 终端中使用空格?
最佳答案
是的,你只需要逃避它。在您的情况下,程序将“上升”视为两个参数。
试试这个:
./try go\ up
关于c - 字符串比较的空白问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12062968/