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

Problem 2 (40 points): Word Search We will implement a word search game for this

ID: 3805999 • Letter: P

Question

Problem 2 (40 points): Word Search We will implement a word search game for this problem. The DataFile.txt contains a word file search puzzle that is size 201 x 100 (201 lines and each line has 100 characters)-all characters are uppercase This puzzle is made simple in that all words are hidden horizontally, and in forward order (i.e. no words are written backwards, nor vertically nor diagonally). Although the words are all hidden in forward order, they may occur multiple times on any given line (see sample code execution) Since there are no lowercase characters in the puzzle, you should not worry about converting lowercase to uppercase or vice versa. A sample portion of the puzzle is TPAABBINPUMADSSY ETPL which is difficult enough to search as it is. The words that are hidden in the puzzle are: P FPRINTF, FsCANF, DOUBLE, MAIN, DOWHILE, FGETS, INT, IF, WHILE, ENGINEERING, RETURN, CHAR, FCLOSE, ELECTRICAL, ECE, VOID, FLOAT, FOR write a C program that will search the text file for the word entered by a user. Your program should a) read from the text file one line at a time (Hint: use fgets) b) print to the screen bl) the word that is currently being searched. b2) number of times the word was found on the line b3) the line number and the line where the word was found. c) b4) how many times in total the word was found in the puzzle or the word is not found be interactive such that it asks a user whether he she wants to search the puzzle with a new word See sample code execution. a

Explanation / Answer

PROGRAM CODE:

/*
* StringPuzzle.c
*
* Created on: 28-Mar-2017
* Author: kasturi
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void my_strcpy(char In[], char out[], int start, int L)
{
int i, counter = 0;
for(i=start; i<(L+start); i++)
{
   out[counter++] = In[i];
}
out[counter] = '';
return;
}

int search_current_line(char Line_Str[], char word[])
{
   int wordLength = strlen(word);
   int lineLength = strlen(Line_Str);
   int count = 0;
   if(wordLength>lineLength)
       return 0;
   for(int j=0; j<lineLength; j++)
   {
       char out[wordLength];
       my_strcpy(Line_Str, out, j, wordLength);

       if(strcmp(out, word) == 0)
           count++;

   }
   return count;
}

int main()
{
   char Line[100], word[50];
   int FileLength = 3;
   printf(" Enter a word you want to search for: ");
   scanf("%s", word);

   FILE *fp = fopen("DataFile.txt", "r");
   int totalCounter = 0;
   int linenumber = 1;
   for(int i=0; i<FileLength; i++)
   {
       int counter = 0;
       fgets(Line,100,fp);
       counter = search_current_line(Line, word);
       if(counter > 0)
       {
           printf(" Found %s %d times on line %d ", word, counter, linenumber);
           printf(" The line is: %s", Line);
           totalCounter += counter;
       }
       linenumber++;
   }
   if(totalCounter > 0)
       printf(" The string: %s was found a total of %d times in the puzzle.", word, totalCounter);
   else
       printf(" The string: %s was found NOT found in the puzzle.", word);
}//please test with your data file

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote