Thread: C question
View Single Post

  #1 (permalink)  
Old 03-05-2006, 04:32 AM
TOP TOP is offline
Junior Member
 
Join Date: Feb 2006
Posts: 4
Rep Power: 0
TOP
Default C question

You are required to create a program which simulate command grep in
Unix. Let us call it grep2. grep2 will take a set of parameters. The first parameter is the
pattern to be searched. The rest of the parameters are just file names. grep2 will search in
each file for those line( that contain( the pattern. The output of grep2 is in the
following format:
filename: the line containing the pattern
Your grep2 needs to check the number of parameters. If the number of parameters is not
correct, grep2 displays its usage. For each specified file name, if grep2 cannot open it for
reading, it displays the error message telling its user the failed file name. You also need
to do any other possible checks.
Since you do not know how many characters there are on each line, you need to
dynamically allocate memory for each line read from a file.
Reply With Quote