#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;
}
Prepare an array to hold the tokens
scan for first non blank char in the line, and pass it to the parser who will take the non-blank chars into a token, and advance to the next blank
Input
led set 3 on
Expected Output
led set 3 on