Starting from:

$30

COM1002 Lab 7 -Solved

Write a program that reads a set of dic1onary words and their scores from the standart input and stops reading a6er it reads “END” keyword. What you will then do is to read the following query strings (one or more) un#l the EOF and print the scores associated with the query strings if it is included in the dic1onary.

Look at the example to understand beEer.  

For example: Assume that the input is given as:  

> book 30 pencil 20 desk 80 END pencil ball desk cup  

*  You will search the query strings: {“pencil”, “ball”, “desk”, “cup”} within your dic1onary. When you find them in your dic1onary (with an exact match), print the corresponding score of that item. Then you will print a newline (‘\n’).  

*  You will not print anything for a query string if the query string is not in your dic1onary.

The output will be: >pencil 20 desk 80

Input Format: 

{<word>[white-space]<score>[white-space]}1 or more END [white-space]{<query-string>}1 or more 

Output Format: 

{<word>[SPACE]<score>[NEWLINE]}1 or more 

*You can assume that the number of words in your dic1onay (reference word list) will not exceed 20. The words (strings) will not exceed 30 characters. 

*You can use <string.h> library func1ons if you like. 

Hint: 

Reading un1l the EOF:  

while(scanf(..) != EOF)

{  

// do something here

}

Test your program using input redirec1on! Prepare an input file to test your program and run it as follows, assuming that your executable is named as lab7: 

>./lab7<input1.txt 

More products