Answer to Quiz 12 Fri 20 Apr 2001

  1. With the UNIX command grep we can search in a file for strings that match a given string. For example,
       prompt> grep name file
    
    will display on screen all lines in file that contain the string name. The function void callgrep ( const char *string, const char *filename ) calls the grep command with as arguments the actual content of the variables string and filename. Give the implementation of callgrep below :
        void callgrep ( const char *string, const char *filename )
        {
           char *cmd;
     
           sprintf(cmd, "grep %s %s", string, filename);
           system(cmd);
        }
    
  2. Consider the following makefile :
    all: P1 P3
    P1: P2
            @echo n
    P2:
            @echo e
    P3:
            @echo d
    
    What is printed on screen when make is typed?
    e
    n
    d