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

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

ID: 3669139 • Letter: C

Question

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

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

Explanation / Answer

Hi i will write a simple JAVA program to solve a mouse escape route from a maze, by reading from a text file.With this example you will get an idea for working on maze concept.