A pattern recognition program must print all lines containing the patter if the input is find pattern. If the input is find -x pattern, the program must print all lines except the lines containing pattern.
// .....
switch(c)
{
case 'x':
except=1;
break;
// ......
}
// ......
while(getline(line,MAXLINE)>0)
{
line_num++;
if( (strstr(line,*argv)!=NULL) != except)
{
if(number)
printf("%ld:",linenum);
printf("%s",line);
found++;
}
}
// ......
In the above code from K&R except can either be 1 or 0. How does if(strstr...)
block functions effectively to handle -x ?