#include
#include
#define MAXLINE 1000
#define getline _getline
int getline(char *line, int max);
main(int argc, char *argv[])
{
char line[MAXLINE];
int found = 0;
if (argc != 2)
printf("Usage:\n");
else
while (getline(line,MAXLINE)>0)
if (strstr(line,argv[1])!=NULL){
printf("%s",line);
found++;
}
return found;
}
int getline(char *s, int lim)
{
int c;
char *t = s;
while (--lim > 0 && (c = getchar()) != EOF && c != '\n')
*s++ = c;
if (c == '\n')
*s++ = c;
*s = '\0';
return s - t;
}
我理解不了这个程序中这一段
if (strstr(line,argv[1])!=NULL){
printf("%s",line);
strstr返回一个指针,这个指针指向line里面匹配到的内容
那么为什么打印line会打印出这个匹配的内容呢?