#include <stdio.h> #include <ctype.h> void parse_shell_input(char *line) { // Your logic here char *start = line; //start pointer set to starting of line while(*line){ if(*line == ' '){ *line = '\0'; if(*start != '\0') printf("%s\n", start); start = line + 1; } line++; } *line = '\0'; //last token printf("%s", start); } int main() { char line[101]; fgets(line, sizeof(line), stdin); parse_shell_input(line); return 0; }
Iniitalize a start pointer pointing to the starting character address of the string.
Loop thorugh the input string, each time a space is encountered
Test Cases
Test Results
Input
led set 3 on
Expected Output