I was going through the grep.c file (at https://www.cs.princeton.edu/~bwk/tpop.webpage/grep.c) from Kernighan & Pike’s book The Practice of Programming.
If I search for regexp
^c*
in a file which contains nothing but
d
it will send these to match() function which will send ("c*", "d") to matchhere function.
matchhere sends (‘c’, "\0", "d") to matchstar which in turn sends ("\0", "d") to matchhere function. This will return 1 to the main grep() function
Where am I taking the values incorrectly?
Returning 1 is the correct answer. The regular expression
^c*matches zero or more copies ofcat the beginning of a line, and a file containingdcertainly matches that; in fact, every line of every file will match that.