Write a C program that asks the user for a filename ending in “.txt”. The program should read this file
and then ask the user to input a
search string. The program should tell the user whether the search
string was found or not.
Implement this so that only exact matches are counted. That is, each character in the search string must
be exactly matched in the file
for the program to return success
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char name[50];
char buf[100];
char text[10000];
int fl = 1;
FILE *inf_file;
while(fl)
{
printf("Input name of file: ");
scanf("%s", name);
inf_file = fopen(name, "r");
if(inf_file == NULL)
printf("File not found!\n");
else fl = 0;
}
while(fgets(buf, sizeof(buf), inf_file))
strcat(text, buf);
printf("Input a search string: ");
scanf("%s", buf);
if(strstr(text, buf) == NULL)
printf("search failed!\n");
else printf("String was found! Success!\n");
return 0;
}