|
こんにちはmkと言います。
○質問
プログラミング言語CのP.143 5.10のプログラムですが、
while (c = *++argv[0]) { の行の *++argv[0]
の意味がわかりません。
argv[0] の数値は書き換えてよいのでしょうか。
また、*argv[1] = 'a'; *(argv[1]+1)
= '\0'
等の書き換えも可能なのでしょうか。
○プログラムリスト
#include <stdio.h>
#include <string.h>
#define MAXLINE (100)
/* getline: sに行を入れ,長さを返す */
int getline(char s[], int lim)
{
int c, i;
for (i = 0; i < lim - 1 && (c = getchar()) != EOF && c != '\n'; ++i)
s[i] = c;
if (c == '\n')
s[i++] = c;
s[i] = '\0';
return i;
}
/* find: 最初の引数にあるパターンとマッチする行を表示する */
int main(int argc, char *argv[])
{
char line[MAXLINE];
long lineno = 0;
int c, except = 0, number = 0, found = 0;
while (--argc > 0 && (*++argv)[0] == '-') {
while (c = *++argv[0]) { /* この行が良くわかりません */
/* char *argvtemp = argv[0]; */
/* while (c = *++argvtemp) { */
/* としたほうが良いのでしょうか */
switch (c) {
case 'x':
except = 1;
break;
case 'n':
number = 1;
break;
default:
printf("find: find -x -n patttern\n");
argc = 0;
found = -1;
break;
}
}
}
if (argc != 1)
printf("Usage: find -x -n pattern\n");
else
while (getline(line, MAXLINE) > 0) {
lineno++;
if ((strstr(line, *argv) != NULL) != except) {
if (number)
printf("%ld:", lineno);
printf("%s", line);
found++;
}
}
return found;
}
○実行例
C:\home\c\programmingc>bcc32 myfind.c
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
ex0510find3.c:
警告 W8060 ex0510find3.c 25: おそらく不正な代入(関数 main )
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
C:\home\c\programmingc>myfind.exe -n argv < myfind.c
18:int main(int argc, char *argv[])
23: while (--argc > 0 && (*++argv)[0] == '-') {
25: while (c = *++argv[0]) { /* この行が良くわかりません */
26: /* char *argvtemp = argv[0]; */
27: /* while (c = *++argvtemp) { */
50: if ((strstr(line, *argv) != NULL) != except) {
C:\home\c\programmingc>
○実行環境
OS:WindowsXP Home SP1
コンパイラ:Borland C++ 5.5.1 for Win32
よろしくお願いします。
|