Implement a Simple Shell Command Parser

Code

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

void parse_shell_input(char *line) {

    while (*line != '\0')
    {
        int seen_space = 0; 
        while (*line == ' ' && *line != '\0')
        {
            line++;
            seen_space = 1;
        }
        if (*line == '\0') break;

        if (seen_space == 1) printf("\n");

        if (seen_space == 0)
        {
            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