# 2021-04-06 `gyes00205` ## 測驗 `1` 從 `c + 1` 的位置開始為 input 的內容,而 `*c` 的值為 0 。 ```cpp= int main() { while (1) { prompt(); char buf[512] = {0}; /* input buffer */ char *c = buf; if (!fgets(c + 1, sizeof(buf) - 1, stdin)) exit(0); for (; *++c;) /* skip to end of line */ ; run(c, 0); } return 0; } ``` * e.g. 輸入 `vim` ``` c c+1 c+2 c+3 c+4 0 v i m \n ``` ```cpp static void run(char *c, int t) { char *redir_stdin = NULL, *redir_stdout = NULL; int pipefds[2] = {0, 0}, outfd = 0; char *v[99] = {0}; char **u = &v[98]; /* end of words */ for (;;) { c--; if (is_delim(*c)) /* if NULL (start of string) or pipe: break */ break; if (!is_special(*c)) { c++; /* Copy word of regular chars into previous u */ *c = 0; while(!is_special(*--c)); *--u = c + 1; } if (is_redir(*c)) { /* If < or > */ if (*c == '<') redir_stdin = *u; else redir_stdout = *u; if ((u - v) != 98) u++; } } ... } ```