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

C programing. Maze Traversal: The following grid is an array representation of a

ID: 3696812 • Letter: C

Question

C programing.

Maze Traversal: The following grid is an array representation of a maze.

The ‘#’ symbol represents the walls of the maze, and the period (.) represents squares in the possible path through the maze. S is the starting location (Start) and E is the ending location (Exit)

There is a simple algorithm for walking through a maze that guarantees finding the exit (if there is an exit). If there is no exit, you will arrive at the starting location again. Place your hand on the wall to your right and begin walking forward. Never remove you hand from the wall. If the maze turns to the right, you follow the wall to the right. As long as you do not remove your hand from the wall, eventually you will arrive at the exit of the maze. There may be shorter path than the one you have taken, but with this algorithm, you are guaranteed to find your way out of the maze.

Write a program that will get you out of a maze similar to the above pictured maze. Your program must read the maze from a file. Organize your program for easy debugging and understanding using functions, arrays and other features of the C programming language we have learned so far to accomplish the task.

Print out the maze after each step has been taken and mark each current position with the letter x.

Test your program for the case where there is an exit and for the case where this is no exit (in which case you will end up back at the starting location)

Explanation / Answer

IMultipart question but i did read from file and pseucode, hope it helps! Good Day.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/wait.h>

char **laberi;

char **maketestMatrix()
{  
   char line0[] = {'#','#','#','#','#','#','#','#'};
  
   char line1[]= {'#','.','#','.','.','#','.','#'};

   char line2[] = {'S','.','#','#','.','#','.','E'};
  
   char line3[] = {'#','.','#','#','.','.','.','#'};
  
   char line4[] = {'#','.','.','.','.','#','.','#'};
  
   char line5[] = {'#','#','#','#','.','#','#','#'};
  
   char line6[] = {'#','.','.','.','.','.','.','#'};
  
   char line7[] = {'#','#','#','#','#','#','#','#'};
  
   char **voidmatrix=(char**)malloc(8*sizeof(char));
    for (int i= 0; i<8;i++){
       voidmatrix[0][i] = line0[i];
   }
   for (int i= 0; i<8;i++){
       voidmatrix[1][i] = line0[i];
   }
   for (int i= 0; i<8;i++){
       voidmatrix[2][i] = line0[i];
   }
   for (int i= 0; i<8;i++){
       voidmatrix[3][i] = line0[i];
   }
   for (int i= 0; i<8;i++){
       voidmatrix[4][i] = line0[i];
   }
   for (int i= 0; i<8;i++){
       voidmatrix[5][i] = line0[i];
   }
   for (int i= 0; i<8;i++){
       voidmatrix[6][i] = line0[i];
   }
   for (int i= 0; i<8;i++){
       voidmatrix[7][i] = line0[i];
   }
  
   return voidmatrix;
}

void chegg()
{
char **laberi = maketestMatrix();
// char **laberi = matrixfromfile; ACTIVATE HERE TO READ FROM FILE, testing with maketestMatrix (size 8x8 FOR NOW
if(solution (laberi)== 1){ printf("there is an exit"); return 0;}
if(solution (laberi) == 0){ printf("no exit"); return 0;}
  
}

int solution(char **pro){
   int i; int j; // we will need to know the diment of arry for now
   // PSEUDOCODE FROM HERE:
   // LOCATE S IN THE ARRAY
   /* YOU NEED TO READ THE ROW + 1 TO LOOK FOR "#"
   YOU NEED TO VALIDATE THAT ARRAY[CURRENT ROW][COLUMN +1] IS "#" IF THATS THE CASE MOVE TO CURRENT ROW-1
   REPEAT UNTIL FIND EXIT ( PROBLEM SAYS WE HAVE AN EXIT SO NO BORDER CASES :)
   */

   return 0;
}

char **matrixfromfile(int size){ // you can cuztomize the matrix size if needed
   double** matr=malloc(size*sizeof(double*));
   int i; int j;
   for(i=0;i<size;++i)
   matr[i]=malloc(size*sizeof(double));

      FILE *file;
      file=fopen("abcd.txt", "r"); // your route here
      char **matrix=(char**)malloc(8*sizeof(char));
  
   for(i = 0; i < 1000; i++)
      {
          for(j = 0; j < 4; j++)
          {
           if (!fscanf(file, "%c", &matr[i][j]))
               break;
          }

      }
      fclose(file);
   }

int main ()
{  

   chegg();     
    return 0;

}