103. Implement a Simple Shell Command Parser

Back To All Submissions
Previous Submission
Next Submission

Code

#include <stdio.h>
#include <ctype.h>
#include <string.h>
void parse_shell_input(char *line) {
    char buff[100];
    strncpy(buff, line, sizeof(buff)-1);
    buff[sizeof(buff)-1] = '\0';

    char *spaceAddr = strtok(buff, " ");
    while (spaceAddr != NULL) {
        printf("%s\n", spaceAddr);
        spaceAddr = strtok(NULL, " ");
    }
}


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

    parse_shell_input(line);
    return 0;
}

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote