All submissions

Implement a Simple Shell Command Parser

 

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

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

    while (line[i] != '\0' && line[i] != '\n') 
    {
        if (isspace(line[i])) 
        {
            if (in_token) 
            {
                putchar('\n'); // End of a word
                in_token = 0;
            }
        } 
        else 
        {
            putchar(line[i]);
            in_token = 1;
        }
        i++;
    }
}

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

    parse_shell_input(line);
    return 0;
}

 

 

 

Loading...

Input

led set 3 on

Expected Output

led set 3 on