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 count =0;
    while(*line != '\0')
    {
        if(*line == ' ')
        {
            if(count == 0)
            {
                printf("\n");
                count++;
            }
        }
        else
        {
            count =0;
            printf("%c",*line);
        }
        line++;
    }
}

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

    parse_shell_input(line);
    return 0;
}

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote