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) {
    int i = 0;
    int j = 0;
    char str[100];
    while(line[i] != '\0')
    {
        if(line[i] != ' ')
        {
            printf("%c",line[i]);
            j = 0;
        }
        else
        {
            if(j == 0)
            {
                printf("\n");
                j++;
            }
        }
        i++;
    }
}

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

    parse_shell_input(line);
    return 0;
}

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote