Question: We will implement a word search game for this problem. The file DataFile.txt contains a word search puzzle that is size 201 x 100 (201
We will implement a word search game for this problem. The file DataFile.txt contains a word 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
which is difficult enough to search as it is.
The words that are hidden in the puzzle are: PROGRAMMING, 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
b1) 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. b4) how many times in total the word was found in the puzzle or the word is not found
c) be interactive such that it asks a user whether he/she wants to search the puzzle with a new word. See sample code execution.
d) use the following given user-defined function:
A command that you might find useful is: Assuming that fp is declared as FILE *fp; you can rewind the file pointer back to the beginning of the file using
rewind(fp);
int search_current_line(char Line_str[], char word[])
//This function searches a test string (Line_str) for a word
//and returns number of times the word is found on Line_str
2
A function that you might find useful is: void my_strcpy(char In[], char Out[], int L){
int i; for(i = 0; i Out[i] = In[i]; Out[L] = '\0'; return; } Sample Code Executions (Red entered by a user) Enter a word you want to search for: MAIN Found MAIN 3 times on line 82 The line is: MAINBZFHNJLYOXGNGSSGNVEXJITUTSMAINZHJRJMCZKBUITWQKFZVDBPDITNNKOGQZHDTC LTMAINEYUWPYKJCQSHKGYSNAZJFYJ Found MAIN 1 times on line 94 The line is: ZFDVDNEEPTFWGIAZYKZHPKZWZMSXDMAINL YNZEZFQOQJW ASFVUQAKQQMSMULJJHXKZLG VWXOEELYDSOSCHKONUACTCXAPTDMNKZ The string: "MAIN" was found a total of 4 times in the puzzle. Do you want to search another word (q to quit)? y Enter a word you want to search for: TEST The string: "TEST" was NOT found in the puzzle. Do you want to search another word (q to quit)? y Enter a word you want to search for: PROGRAMMING Found PROGRAMMING 1 times on line 43 The line is: ABOZMAKPCFBGZZXPROGRAMMINGUOURMWESVJJGDHRTNRAPOODNDSZTBZZSAVRQPWWA MRRUBUXPGPJSWIUVHLSHTOULWEVTVZHHB This function copies one string to another. However, it can copy a portion of a string. For example, if you were working with a findstring of length 7, and a string named str that contains 012345 Here is an example string and you want to compare only the 5th through the 11th elements to the findstring, then you would call my_strcpy(&str[4], outstr, 7); Then outstr contains 45 Here and is of length 7. Now outstr is ready to be compared to the find string using strcmp which will compare2 strings of the same length. 3 Found PROGRAMMING 2 times on line 54 The line is: DPUIHKVUOVKWNORNQPROGRAMMINGKODKWFFPREYOUCNXXOPDNNUPLFQDQXMCRVRNW PIYGQJYRJLECDDV AKOPKMMTPROGRAMMING The string: "PROGRAMMING" was found a total of 3 times in the puzzle. Do you want to search another word (q to quit)? y Enter a word you want to search for: IF Found IF 1 times on line 3 The line is: ZYJCTQVIHSZICSMMODWDNXIVKLKGPJOVGKHJUPZEDAIQXJQVYBQCXRBHIFIXCHDLPCCRAG NESNRYYACYNPIIBMRNWSWAIZIPLUF Found IF 1 times on line 11 The line is: OVKWNCVGIIIXGMTGUIUOLIWNZNTGBQSVNEHSLJERSHVNZXY AAXECOEPOZDVBZPCFJMBLZK FBLLKHDIFBTDUACNPQRPKCNDYDLSY Found IF 1 times on line 17 The line is: GLTSKOQUYNEXKSSCJRPGDSXCEGYYEUIFXQCLYAOKJONYUGBHQISHPNBABBMHZOWPDXZLB YXFLYJERRZRDCESTNGTAMTVFSRNHDF Found IF 1 times on line 25 The line is: TDSVTHAKDYNDUHCKKJILABGW ANOUZGESMMNBZZMJRNZMXOISMUXBSORSXQZYYYCBIFTO TYFBNHZZJMJPLVYTQEIUQUJUUGHXOAS Found IF 1 times on line 30 The line is: AYLXNIYFSJBGUJDMBJCSTOYMXONTOJWIFDAENCTISVMTSJWMGOCBCMEDPNZHPTNOPPEPDN RAYIYISNTAUIHJGSRIHGTYGMMKZRC Found IF 1 times on line 33 The line is: PQWXZYHSCAMYHWGGEIUOFMUZOBUZUCXUPEGSBKVXJFYUTPZLZEOQTWFFWGOYFCVTRLX MLZPSWVKJNLHDEZENXHPKQYJFFILZVIF Found IF 1 times on line 36 The line is: WWWIMIXYFZQYEIUJBTRUWBJUUAKSWEAOAMFNZAWMZXMECVDEDQRYLSTFPAHHGPVJZWD ZMDHYJQHVWYORSDWCXXVTXHIFHONMMNI Found IF 1 times on line 45 The line is: OWCXBEPGSOBWSDZJPROBETOWHWOAPXWYHTSYMOUPCXWBZKYJAVLKYGSTFBEPLEGNIFR HVKKKABMLGLQYRXPGOPRZEBCQZWNNYGI 4 Found IF 1 times on line 55 The line is: ZFGKREOHTHCVYTKZVTDYHAYMFHRPEXTIFYNRDEXAUEZXGYWMMGQZXJHJUTBSMBQZJUFT FMVHWJMLNXCWVMJDVHXEEAUZDIHVIDI Found IF 1 times on line 61 The line is: IA TJUBGBRDPKVERWEXQYZZGXTWPIFOTGALFGNFNPCUMUZYUPDONCZHL TPVRFXODURIGRR RUHAA VNSIKXZPCJGHZZCKUQVRQDMBM Found IF 1 times on line 62 The line is: LONWTGLUFW AMKKKBGSVZPPTNPYYQBPNOL VNZYQVGMVMJJITHGFTDHJUONBUT AEGLXBQ NYBVBPARZVBYEVCIFWGDOQXCOIAEHMJE Found IF 1 times on line 70 The line is: CWSGURXTDEWNSKREFWOJPTZTLZPSWKYCCVXPTGQKRFHDPURVEQQVQGNIFRLRQSIIIODWT KVJPRFZZUQHOHUQWLPIRYDPLATPJMM Found IF 1 times on line 72 The line is: FVNUQJKVLTIILZUVBGNBRPYTFFSCFDARIRBWLSLLOYDTSNMSQZHEFBKGFINAILLOPFDAABIF PJXJPSRRCDTBTGWKMVDUDJZGJQJ Found IF 1 times on line 88 The line is: XRNUBQNNQVTOAWIFVSHAPXYVKGACPLVBUSLPYSOUZYAISDRTDCGUYPMXIATOMYMFUAY BMEZXVQBXBJJBCZSEVEITJIDURVCYCKP Found IF 1 times on line 108 The line is: FVWULETGDSNJDSVYMSZVYQDGHTITIFGTIKNFFOKKEJFPQRRLMEXKXUHKZSMWLDBGGY AAJ ABOSUNVYDYYECNYEXNLGXJIPEZHVHF Found IF 1 times on line 121 The line is: QVLQTWQUCTZAEHTHMPEHMGHTTWHJYY ABTIJWQFEGJMJPVGORSBKIEOBFKIHACOEIJYDIEA WSVBGZINLIFKTNTGQHKAEZAXKEJJV Found IF 1 times on line 148 The line is: MIOUGBGIFFVBKISLUDFLSPPOJPXXFFFCIVHWZISFHCDEUVRHIYFJGGTCACSMANQKFKIVVMVC ZJOGDSCRFIXUZVNZKMWZXYJIQDP Found IF 1 times on line 150 The line is: OYEHWKQJQARTSQHOWCILIYEBLZIFLEYVDREJSWTBEVKLTGFFDZKZPMLPIWWYFJNLDDVUMF HGIMLUDPEZJNUVFJCPQXOKNETMLNX 5 Found IF 1 times on line 157 The line is: MEDMBQWTDXHRBCKPQALKHIERBHKXXJOJREJEIPAOPLRUSYHYXRGQAJEIHTPZKCQLDJTZZZ ASBKTHSZUTQWYRJYTJQGKSGBPZKIF Found IF 1 times on line 158 The line is: YVMUGCFIYUEILQFZQFISOUMVZVFSARBIFODVUAZGGTXUFVGZRYIAZNWIHPEUHJUYHAZCUL QWXNCOHMAJNORUGPNHMWIPQMXEROP Found IF 1 times on line 189 The line is: WIFPWFFRACMPIOUGFYZVOKDCIWZSYNRRODFMMOMLGRXJDRKOKHNUSYIUVDFLONTULUA OFELSEMCOKMHDOPBHTJXKSQYZSQYOAIG Found IF 1 times on line 191 The line is: OLOHWEIIWNOBHTODZSILJDGBVCFTUFHTGIWZCXPAZABIYBCDGFMCLOCDHSGWISYOKDFOO ERRPHNDDURGLIFVORFPXAKKRPEVNHA Found IF 1 times on line 192 The line is: KXUCORVXEMOKCLJWBGIFKZNETFVWTBGSTSNWXHTMPRNCEBJRYZJBVUVWPIZYUHMQGLFG XKBRSSANBXXXRPMRREEKLKODHJYLYCK Found IF 1 times on line 197 The line is: VTOVICERQAKZYITRZVQBBGKEYMQETLMMHXDCKFQKQPVAPMMYHKPAZMENRLTWZVVTGU DYZLIFZHYBYBBSPJTXUJCLCPPGJBFUNXG Found IF 1 times on line 200 The line is: MFXYUOUZJKSNJDVNCZLUWBHDONUOAQEDFZRGAKDRKGKQKLWODCEBLMRMWDBUUOVQP BLPSEQKFLYNVUNZIKOMOSXHCSCHCQMLXIF The string: "IF" was found a total of 25 times in the puzzle. Do you want to search another word (q to quit)? y Enter a word you want to search for: VOID Found VOID 1 times on line 155 The line is: ZCGLUHXEKOWJRNVHDNIOKUBVOIDQQAOZCUHYFMLQQRQLZQEEMKKZKRIJBXRGMRQLCXP ODDWUGFYTFGDKZZAOONSSKVWVOKQIMKG The string: "VOID" was found a total of 1 times in the puzzle. Do you want to search another word (q to quit)? q
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
