#include <stdio.h> #include <ctype.h> int extract_token(char *str, char *token) { int i; for (i=0; (str[i] != ' ') && (str[i] != '\0'); i++) { token[i] = str[i]; } token[i] = '\0'; return i; } void parse_shell_input(char *line) { // Your logic here char token[100][100]; int i, j, count; for (i=0, j=0; (line[i] != '\0'); i++) { if ((line[i] != ' ')) { i += extract_token(&line[i], token[j]) - 1; j++; } } count= j; //printf("%d\n", count); for (i=0; i < count; i++) { printf("%s\n", token[i]); } } int main() { char line[101]; fgets(line, sizeof(line), stdin); parse_shell_input(line); return 0; }
Test Cases
Test Results
Input
led set 3 on
Expected Output