All submissions

Implement a Simple Shell Command Parser

Code

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

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

    while(*line != '\0')
    {
        if(*line == ' ')
        {
            word[i] = '\0';
            printf("%s\n", word);
            i = 0;
            line++;
            while(*line != '\0' && *line == ' ')
            {
                line++;
            }
        }
        else
        {
            word[i++] = *line;
            line++;
        }
    }

    word[i] = '\0';
    printf("%s", word);
}

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

    parse_shell_input(line);
    return 0;
}

Solving Approach

 

 

 

Loading...

Input

led set 3 on

Expected Output

led set 3 on