Implement a Simple Shell Command Parser

Code

#include <stdio.h>
#include <ctype.h>
int i=0;
void parse_shell_input(char *line) {
    // Your logic here
    char *str;
    str = line;
    int len;
    for(len=0;str[len]!='\0';len++);

    int i;
    int count =0;
    for(i=0;i<len;i++){
        if(str[i] == ' ' && str[i+1] != ' '){
            printf("\n");
        } 
        else if(!(str[i] == ' ' && str[i+1] == ' ')) printf("%c",str[i]);
        
    }
    
}

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