Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, please write a C Program for the following: If possible PLEASE COMMENT im

ID: 3600818 • Letter: H

Question

Hello, please write a C Program for the following:

If possible PLEASE COMMENT important steps, THANK YOU IN ADVANCE!

Problem 1 (35 points): grep We wish to create a utility that will search a text file for a specified string. Unix has a line utility that does this called grep, which is a funny acronym that stands for globally searchoa regular expression and print. Write a C program that will search a text file for a specified string. Your program should a) Prompt the user for the name of the file to be searched. b) Prompt the user for the string to be found in the file. c) Print the name of the file searched. d) If the string is found then print the entire line of text where the string was found and the line number. e) Print the number of times the string was found Assumptions for this assignment Assume that all strings have a maximum length of 200 characters .Assume that each line of the file being searched is no more than 200 characters long. . Assume case sensitivity For example, if the file being searched contains OK and the string to find is ok thena match is not found; i.e. you do not need to worry about changing uppercase characters to lowercase or vice versa

Explanation / Answer

below the code for same which is easy to understand , if not comment me .

#include <stdio.h>

int main()
{
char nome_arq[20];

printf("Tell me the name of file: ");
scanf(" %s", nome_arq);

FILE *fp = fopen(nome_arq, "r");

if(!fp) return 0;

char palavra[40];

printf("Tell me the word: ");
scanf(" %s", palavra);

while(!feof(fp)) {
char palavra2[40];

fscanf(fp, " %[^' ']", palavra2);

if(!strcmp(palavra, palavra2)) {
char linha[400];
fgets(linha, 400, fp);
printf("%s ", linha);
}
}

return 0;
}