Many pictorial files, such as jpegs or gif files, are stored in a compressed format that eliminates redundant information. This compression reduces the size of the files, which you may have noticed can be quite large, even when compressed. In this program you are going to take a compressed file of a maze and re-create the diagram for that maze. The maze will have walls that are drawn with a '#', corridors that are drawn with spaces, and players, monsters, and treasure that are drawn with various symbols. Here is a sample maze:
############################# # @ # # ##### ##### $ ###### # ##### ## # # ### !## ####### # # ## ##### ####### # # # # # O $ D # ##################################Our compressed representation of the maze will be as follows:
For example, the above maze would be represented by the input file:
9 0-28 0 28 0 4-8 12-16 28-33 0 4-8 13-14 33 0 5-7 13-14 20-26 33 0 6-7 12-16 20-26 33 0 7 33 0 33 0-33 @ 1 4 $ 2 21 ! 4 12 O 7 11 $ 7 19 D 7 25Your program will take a single argument, the name of the maze file, as input and output the appropriate maze diagram.
Required Design
Hints
Name your file maze.c. No error checking is required for this program.
You may have played games in which a high score list is printed at the end of the game. More sophisticated games may allow you to select a difficulty level and then keep a high score list associated with each difficulty level. You will write a program named score.c that creates a high score list for a game with 15 difficulty levels, ranging from 1-15. Your program will take two command line inputs, a score file and an integer representing the number of high scores to print for each level. It will produce as output a sorted high score list for each level. The scores will be printed from highest to lowest. Each line of input will have the format:
player_id level scoreplayer_id is a 6 character or less id, level is an integer between 1 and 15, and score is a positive integer that is less than 100000.
The output should have the following format:
Level x:
player_id score
...
Level y:
player_id score
The level number
should be in a field two digits wide, player_id should
be in a field six characters wide, and score should be in a field
5 digits wide. level and score should be right-justified and
player_id should be left-justified.
As an example, given the input file:
bvz 4 8585 bvz1 11 53 mary 4 58685 jack 4 838 marvin 8 6869 smiley 4 15868 ardvar 8 68and the command:
score score_file 3your output should be:
Level: 4
mary 58685
smiley 15868
bvz 8585
Level: 8
marvin 6869
ardvar 68
Level: 11
bvz1 53
Note that levels without scores are suppressed and all scores for a level
are printed if the level does not have the requested number of high scores.
The only error check you need to make is whether or not the line has exactly three fields. Print an error message if the line does not have three fields and discard it.
Required Design:
NAME
listfile - display a fractional portion of the specified file
SYNOPSIS
listfile start_fraction end_fraction filename
DESCRIPTION
listfile copies the lines of filename between start_line and
end_line to the standard output where start_line and end_line are
computed as follows:
start_line = start_fraction * (number of lines in file)
end_line = end_fraction * (number of lines in file)
start_line should be rounded down to the next lower integer and
end_line should be rounded up to the next higher integer. For example, 5.03
will become 5 for start_line and 6 for end_line. Similarly, 5.67 will
become 5 for start_line and 6 for end_line.
Precede each line of output with its line number and a colon (:).
Allocate 6 spaces for the number and right justify the number.
ERROR CHECKING
listfile prints an error message if:
1. either start_fraction or end_fraction is not a valid number,
2. either start_fraction or end_fraction is not between 0 and 1,
3. end_fraction is less than start_fraction, or
4. the file named filename does not exist.
Here are some helpful hints:
double ceil(double number)You will need to cast the return result of ceil to an integer. You will also have to include the <math.h> file in order to use the ceil function and you will have to put a '-lm' flag at the end of your gcc line. For example:
gcc -o listfile ...-lm
double number; int rounded_number: rounded_number = (int)number; // rounds a number down