Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago