Implement a Simple Shell Command Parser

Code

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

void parse_shell_input(char *line) {
    // Your logic here
    char *ch=line;
    while(1){
        while (*ch == ' ' || *ch == '\t' || *ch == '\n') {
            ch++;
        }
        if (*ch == '\0') break;
        while (*ch != ' ' && *ch != '\t' && *ch != '\n' && *ch != '\0') {
            printf("%c", *ch);
            ch++;
        }
        printf("\n");
    }
}

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