Question

Code a program and reads a maze file and exits non-zero if the maze is not...

Code a program and reads a maze file and exits non-zero if the maze is not valid. Or outputs the maze in a frame if it is good.

The name of the file containg the maze is the only command-line parameter to this program. Read that file with the stdio functions, and close it propperly.

A maze is a rectangular array of characters. It is encoded in the file in 2 parts:

header line

The header has 2 decimal intergers separated by white-space (spaces, or tabs).

The first is the number of collums, a literal comma (,) then the number of rows. For example a maze with 10 collums per line, and 8 rows would start with a line:

  10, 8\n

There could be leading white-space, but fscanf(3) will do that for you. I put in the newline so you could see it.

A maze with either dimension < 2 is not a proper maze, and you should output an error and exit with 2 in that case (you don't have to read the rest of the file, but you can if you like).

Maze rows

The maze has implied walls around it. So a space on the edge is passable, but you can't leave the rectangle. Each row represents a map of the maze within that larger box:

  a space is part of a passage

  an octothorpe (#) is a wall.

  the letter s is the start of the maze

  The player is dropped on this square from above.

  the g charater is the goal

  The player escapes to the next level down, or out from this position

Requirements

I would do them in the order presented.

Read the maze into memory you allocate.

You have put it in an array of pointers to an array of a stuct you define.

You have to exit non-zero on any of these conditions

Oh, and a nifty error to stderr would be implied here. And a unique exit code.

--- you could not open the maze file

--- you ran out of memmory to hold the maze

--- the maze is to small (either dimension < 2)

--- the maze has a total start cells that is not 1

--- the maze has no goal cell

--- you ran out of row or column characters

--- a cell has any other character in it (yes even a tab)

Is it not an error to have extra data on the end of the file. We might read more from the file in another assignent, so don't close it in the reader function. #clue

Only if the maze is good, then print it back out

You don't have to output the numbers, just the maze in a frame.

--- box in the maze with --- (dash) bars on the top and bottom

--- show the edges with | (pipe) characts on the left and right edges

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Code a program and reads a maze file and exits non-zero if the maze is not...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • ​​​​​​This program will make Maze game. Please Help in c++ Prompt the user for a file...

    ​​​​​​This program will make Maze game. Please Help in c++ Prompt the user for a file that contains the maze. Read it into a two-dimensional array Remember you can use inputStream.get(c) to read the next character from the inputStream. This will read whitespace and non-whitespace characters Don’t forget to read the newline character at the end of each line Print the maze to the screen from your array You should include a ‘*’ in your maze to indicate where the...

  • I want to make a really simple maze game in Python. I need to use tkinter and GUI to make this ha...

    I want to make a really simple maze game in Python. I need to use tkinter and GUI to make this happened. Under you can see the description of the task, but i need help to getting startet. If there is an other easier way I'm just happy for the help!! task Description: You have to create a maze game. The goal of the game is to get out of the maze. The game should read The maze from a...

  • For this homework you will be making a maze solver. Your program will take in from...

    For this homework you will be making a maze solver. Your program will take in from a file 2 things. The size of the square maze, and the maze itself. The maze will consists of numbers between 0 and 3, where 0 is the start of the maze, 1 is an open path, 3 is a wall, and 2 is the end of the maze. For example a 6x6 maze could be represented by the following file, there will be...

  • PLEASE ANSWER IN C++! Given the starting point in a maze, you are to find and...

    PLEASE ANSWER IN C++! Given the starting point in a maze, you are to find and mark a path out of the maze, which is represented by a 20x20 array of 1s (representing hedges) and 0s (representing the foot-paths). There is only one exit from the maze (represented by E). You may move vertically or horizontally in any direction that contains a 0; you may not move into a square with a 1. If you move into the square with...

  • JAVA Code: Complete the program that reads from a text file and counts the occurrence of...

    JAVA Code: Complete the program that reads from a text file and counts the occurrence of each letter of the English alphabet. The given code already opens a specified text file and reads in the text one line at a time to a temporary String. Your task is to go through that String and count the occurrence of the letters and then print out the final tally of each letter (i.e., how many 'a's?, how many 'b's?, etc.) You can...

  • Write a program that reads in a text file, infile.txt, and prints out all the lines...

    Write a program that reads in a text file, infile.txt, and prints out all the lines in the file to the screen until it encounters a line with fewer than 4 characters. Once it finds a short line (one with fewer than 4 characters), the program stops. For your testing you should create a file named infile.txt. Only upload your Python program, I will create my own infile.txt. Please use a while-loop BUT do not use break, Exit or Quit...

  • Programming Assignment 1 Structures, arrays of structures, functions, header files, multiple code files Program description: Read...

    Programming Assignment 1 Structures, arrays of structures, functions, header files, multiple code files Program description: Read and process a file containing customer purchase data for books. The books available for purchase will be read from a separate data file. Process the customer sales and produce a report of the sales and the remaining book inventory. You are to read a data file (customerList.txt, provided) containing customer book purchasing data. Create a structure to contain the information. The structure will contain...

  • Need help!! Java Eclipse Please provide the screenshot of output of code as well. thank you......

    Need help!! Java Eclipse Please provide the screenshot of output of code as well. thank you... PROGRAM 1 –Linear Data Structure Implementation (Due date: March 5th, 2019, 5% Grade Points) Given the starting point in a maze, you are to find and mark a path out of the maze which is represented by a 30x30 array of 1s (representing hedges) and 0s (representing the foot-paths). There is only one exit from the maze (represented by E). You may move vertically...

  • In this part, you will complete the code to solve a maze.

    - Complete the code to solve a maze- Discuss related data structures topicsProgramming-----------In this part, you will complete the code to solve a maze.Begin with the "solveMaze.py" starter file.This file contains comment instructions that tell you where to add your code.Each maze resides in a text file (with a .txt extension).The following symbols are used in the mazes:BARRIER = '-' # barrierFINISH = 'F' # finish (goal)OPEN = 'O' # open stepSTART = 'S' # start stepVISITED = '#' #...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT