All submissions

Implement a Simple Shell Command Parser

Code

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

void parse_shell_input(char *line) {
    // Your logic here
    while(*line){
        if(*line == ' '){
            if(*(line-1) != ' '){
                printf("\n");
            }
        }
        else    printf("%c", *line);
        line++; 
    }
}

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

    parse_shell_input(line);
    return 0;
}

Solving Approach

if conditional to check current char is space or not, if it is space check for trailing spaces then print newline char. if not spaces just print the ongoing character.

 

 

Loading...

Input

led set 3 on

Expected Output

led set 3 on