#include <stdio.h> void parse_shell_input(char *str){ char token[20][101] = {{0}}; int row = 0, col = 0; for(int i = 0; str[i] != '\0'; ++i){ char c = str[i]; if(c == ' ' || c == '\t'){ if(col == 0) continue; token[row][col] = '\0'; row++; col = 0; if(row >= 20) break; } else { if(col < 100) token[row][col] = c; col++; } } if(col > 0 && row < 20){ token[row][col] = '\0'; row++; } for(int i = 0; i < row; ++i){ printf("%s\n", token[i]); } } int main(void) { char line[101]; if(!fgets(line, sizeof line, stdin)) return 0; for(int i = 0; line[i] != '\0'; ++i){ if(line[i] == '\n'){ line[i] = '\0'; break; } } parse_shell_input(line); return 0; }
Test Cases
Test Results
Input
led set 3 on
Expected Output