WHERE DO I START!?
Write a mygrep program that accepts arguments:
mygrep [-i] [-n] match file1 [file2] [file3] ... [filen]
A grep program will look for occurences of the "match" string in
the files file1, file2, ... filen. Whenever the "match" string is
found, the line where it is found is printed out. The option -i
tells the grep program to make its string comparisons in a
case insensitive manner. The option -n tells the grep program to
print out the line number in the file where the match string is found
along with the file's line. For example, suppose that a file1.txt
contains:
one time around the
block is enough
for me. See me in the IS department.
Assume the name of your program is mygrep, then executing the command:
mygrep is file1.text
will generate:
file1.txt: block is enough
mygrep -i -n is file1.text
will generate:
file1.txt:2: block is enough
file1.txt:3: for me. See me in the IS department.
mygrep can also process multiple files in the same command.
If any of this is still confusing, please ask.
HINTS: strstr, tolower . . . Consider the following tolower example:
char * x="ABCDEF";
char buff[100];
int len = strlen(x);
// Note the following loop copies the null
// terminator
for (int i=0; i <= len; i++)
buff[i] = tolower(x[i]);
cout << buff<<endl;