#include #include #define MAXLINE 1000int getline(char *line,int max);/* find:print lines that match pattern from 1st arg */main(int argc,char *argv[]){char line[MAXLINE];int found = 0;if (argc = 2)printf("Usage:find pattern\n");elsewhile (getline(li

来源:学生作业帮助网 编辑:作业帮 时间:2024/12/02 04:28:59
#include #include #define MAXLINE 1000int getline(char *line,int max);/* find:print lines that match pattern from 1st arg */main(int argc,char *argv[]){char line[MAXLINE];int found = 0;if (argc = 2)printf(
xT_OY*wlvf݇&}hnR}0( "q Z"bjT@M֎C/3-{]S6=ιw$6}8eryʡpT&_ ꝁ ԳgaP,T̖ ʌY EGI(>7K| d3G,ŀ$'S.DO:ghn>$?p8D,A 9iyÜ:\r$!1"y\tp(ᡟ]$TW[>5~uج"$87BЉG.p Cb~6!ſqYg 1U= sV7_Freu=҃U43f o$8}mn4 mԎqWǼ$kEwq`kݶZ -]Ow2f[8=tgCoס쬍xb# qA9 JmvNĽ§$@? i[%4ZeC96wp 7lV s`rZܜna֠kIS6PY $I[ySvZL3UMJmӀ}e\@͊h%twcUJ)j z/ Q]5Zb7K `Eֻ7bh]6YCh$Ȭ@::CrcW}ěa5`, }';=K.pҜjt}$Kfʪ,KNbxhrVGe3 :b lanSfA1:~DAQd'g.A2]`zV]"uo6vlE4!S:y͞~eD.ăco'GGك/x

#include #include #define MAXLINE 1000int getline(char *line,int max);/* find:print lines that match pattern from 1st arg */main(int argc,char *argv[]){char line[MAXLINE];int found = 0;if (argc = 2)printf("Usage:find pattern\n");elsewhile (getline(li
#include
#include
#define MAXLINE 1000
int getline(char *line,int max);
/* find:print lines that match pattern from 1st arg */
main(int argc,char *argv[])
{
char line[MAXLINE];
int found = 0;
if (argc = 2)
printf("Usage:find pattern\n");
else
while (getline(line,MAXLINE) > 0)
if (strstr(line,argv[1]) = NULL) {
printf("%s",line);
found++;
}
return found;
}
此程序中的语句 if (argc = 2)
printf("Usage:find pattern\n");
有什么用呢,实现什么功能呢?
还有一句if (strstr(line,argv[1]) = NULL) 难道line和argv[1]这两个指针相互对应吗?可是并没有对这两个指针进行复制啊?

#include #include #define MAXLINE 1000int getline(char *line,int max);/* find:print lines that match pattern from 1st arg */main(int argc,char *argv[]){char line[MAXLINE];int found = 0;if (argc = 2)printf("Usage:find pattern\n");elsewhile (getline(li
现在的小孩学电脑都是从WINDOWS开始的,没用过DOS,所以不容易理解argc,argv.
用过DOS命令的都知道,DOS命令实际上就是一个程序,比如copy c:\a.txt d:\b.txt,copy就是一个用C语言写好的程序,后面的两个路径名就是程序参数.
main的argc,argv就是用来处理程序参数的.比如copy程序的源代码里面,main函数的argc就是3,argv是个长度为3的字符串数组,分别是"copy","c:\a.txt","d:\b.txt".这样应该就明白了吧.
if (argc != 2)
printf("Usage:find pattern\n");
就是提示你,这个程序要求在命令行模式运行时,必须带1个参数.加上程序名本身,argc正好是2.
strstr(str1,str2)是在str1中查找str2第一次出现的位置,没找到则返回NULL.
argv[1]就是在命令行模式运行时你输入的参数.