私はシェルを作成するこの小さなプログラムを見ています。 parse()
は、文字ポインタline
と文字ポインタの配列argv
を取り、各単語のアドレスをargv
に保存します。私は理解していない何ポインタの配列へのポインタが初期アドレスに戻る
void parse(char *line, char **argv) {
while (*line != '\0') { /* if not the end of line ....... */
while (*line == ' ' || *line == '\t' || *line == '\n')
*line++ = '\0'; /* replace white spaces with 0 */
*argv++ = line; /* save the argument position */
printf("%p\n",*argv);
while (*line != '\0' && *line != ' ' &&
*line != '\t' && *line != '\n')
line++; /* skip the argument until ... */
}
*argv = '\0'; /* mark the end of argument list */
}
はargv
は何とかバック関数が終了した後の最初の単語であるということです。主な機能は、呼び出します。それは、右の前にline
の終わりだったとき
parse(line, argv); /* parse the line */
if (strcmp(argv[0], "exit") == 0) /* is it an "exit"? */
exit(0);
がどのようline
の冒頭にargv[0]
のですか?
'* argv = '\ 0'; '、' argv'は文字列ではなく文字列へのポインタです。 '* argv = NULL'を意味しますか? –
[最小完全な検証可能な例](http://stackoverflow.com/help/mcve)を参照してください。 – user3386109
この質問は、後者と重複しない場合はhttp://stackoverflow.com/q/25769443/694576に関連しています。 – alk