Implement a Simple Shell Command Parser

Code

#include <stdio.h>
#include <ctype.h>
#include <string.h>
void parse_shell_input(char *line) {
    // Your logic here
    int l = 0, r = 0;
    char tmp[102];
    while (r < 100 && line[r] != '\0') {
        while (r < 100 && line[r] != ' ' && line[r] != '\0') r++;
        memcpy(tmp, &line[l], r - l);
        tmp[r - l] = '\0';
        printf("%s\n", tmp);
        while (r < 100 && line[r] == ' ') r++;
        l = r;
    }
}

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