Implement a Simple Shell Command Parser

Code

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

#define TRUE 1
#define FALSE 0

void parse_shell_input(char *line) {
    // Your logic here
    char iter = 0;
    char space_skipped = FALSE;

    while(0 != line[iter])
    {
        while (' ' == line[iter])
        {
            ++iter;
            space_skipped = TRUE;
        }
        if (TRUE == space_skipped)
        {
            printf("\n");
            space_skipped = FALSE;
        }

        printf("%c", line[iter]);
        ++iter;
    }
}

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