Implement a Simple Shell Command Parser

Code

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

void parse_shell_input(char *line) {
    // Your logic here
    int i = 0;

    while (line[i] != '\0') {

        // Skip leading spaces
        while (line[i] == ' ')
            i++;

        // If end reached after skipping spaces, stop
        if (line[i] == '\0')
            break;

        // Print characters of the token
        while (line[i] != ' ' && line[i] != '\0') {
            putchar(line[i]);
            i++;
        }

        putchar('\n');   // end of token
    }


}

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