Computer Science For each of the code snippet given below, identify the error and then write code after fixing the error.   Given code is the simulation of grep -v command. -v prints all lines that do not match a specific pattern. void grep_inverse(char *filename, char *str) { FILE *fp; char buf[buff_size]; fp = fopen(filename, "r"); if(!fp) {        perror(filename); } else {                                while (fgets(buf, buff_size, fp) != NULL) { if ((strstr (buf, str)) != NULL)   printf("%s", buf);                            } } fclose(fp); }

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter7: File Handling And Applications
Section: Chapter Questions
Problem 15RQ
icon
Related questions
Question

Computer Science

For each of the code snippet given below, identify the error and then write code after fixing the error.

 

Given code is the simulation of grep -v command. -v prints all lines that do not match a specific

pattern.

void grep_inverse(char *filename, char *str)

{

FILE *fp;

char buf[buff_size];

fp = fopen(filename, "r");

if(!fp) {

       perror(filename);

}

else {

                               while (fgets(buf, buff_size, fp) != NULL) {

if ((strstr (buf, str)) != NULL)  

printf("%s", buf);

                           }

}

fclose(fp);

}

 

 

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Files and Directory
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage