I wrote a simple application which compare strings. My problem is with white spaces. Here’s the sample code:
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;
}
Now after compiling it with gcc -o try try.c, I run it in my terminal:
./try go up // doesn't show anything
./try down //prints down you go
Is it possible to use white space in the Linux terminal?
It is possible to use white space from the Linux terminal.
Try the following:
For both cases, the system should respond as you expect it to.
The standard shell automatically splits the line into the
argvarray based on the white space. The quotes tell the parser to treat the text as a single string, allowing access to directories like “Program Files.” The backslash escapes the space, telling the parser to treat it as a special character, not a whitespace for splitting the line.