Implement a Simple Shell Command Parser

Code

#include <stdio.h>
#include <ctype.h>

void parse_shell_input(char *line) {
    // Your logic here
    bool found_space = false;
    while (*line != '\n' && *line!='\0') {
        if (*line == ' '){
            if (!found_space) {
                found_space = true;
                printf("\n");
            }
            line++;
            continue;
        }
        found_space =false;
        printf("%c",*line);
        line++;
    }
}

int main() {
    char line[101];
    fgets(line, sizeof(line), stdin);

    parse_shell_input(line);
    return 0;
}

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

led set 3 on

Expected Output

led set 3 on