103. Implement a Simple Shell Command Parser

Back To All Submissions
Previous Submission
Next Submission

Code

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

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

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

    parse_shell_input(line);
    return 0;
}

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote