Question: Need Help. Please. Thank you. I have multifile program. In this program I have to find frequency of word by prompting words from user and

Need Help. Please. Thank you.

I have multifile program. In this program I have to find frequency of word by prompting words from user and find that words from the given file. and count have many times that word appear. In this code I am not able to enter words despite using scanf (I only have to use scanf).

#include "defs.h"

void searchForWord(char allLines[MAX_LINE][MAX_LINE_LEN], int numLines) {

char Words[100]; FILE *in_file = fopen("poe-raven.txt", "rw"); if(in_file == NULL){ printf("Error file is missing "); exit(0); }

printf("Enter the word to search: ");

scanf(" %s",Words);

int count = 0; int i,j,k; int wordLen = strlen(Words);

_Bool isWord = 1; for(i = 0; i< numLines; i++) {

for(j = 0; allLines[i][j] != '\0'; j++) {

//finds the correct first character in the array if(tolower(allLines[i][j]) == tolower(Words[0])){

//Loops while the char are checked and it still may be correct while ((k < wordLen) && (isWord == 1)) {

//breaks loops if end of line is reached if (allLines[i][j+k] == '\0') { isWord = 0; } //increament if the char is correct else if(tolower(allLines[i][j+k] == tolower(Words[k]))) { k++; } else { isWord =0; } }

//make sure the word isn't in the middle of a large word if (isalpha(allLines[i][j-1])) { isWord = 0; } if (isalpha(allLines[i][j+k])) { isWord = 0; } if (isWord ==1) { count++; } } } }

printf("> %s < appears %d times. ",Words,count); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!