Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7821905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:46:57+00:00 2026-06-02T07:46:57+00:00

This is my first question, and yes, it is a homework assignment. I have

  • 0

This is my first question, and yes, it is a “homework” assignment. I have been working on it for hours but cannot get the algorithm to work. The program I’ve written is supposed to contain a function that accepts a 12 by 12 array and finds the path to the end. The main function finds the start of the maze and changes it to an “x” to represent the position of the “player.” The main function then calls the mazePrint function that accepts the array prints it after clearing the screen. Then it calls the mazeTraversal function which accepts the array. The first part of mazeTraversal attempts to locate the position of “x” and replace it with a “.” The next part is supposed to determine which direction the “x” is facing. I used 4, 5, 6, and 8 (west, south, east, and north (look at the number pad)) to represent the way it is facing. Based on the way it is facing, mazeTraversal attempts to determine if there is an open path to the right, then in front, then to the left, and then behind and to then put an X in that position and change the way the x is facing. Something goes wrong after the second move when I run the program. Thanks for any help, and sorry if this is not the place for such questions.

#include <stdio.h>
#include <stdlib.h>

void mazePrint(char *maze[12][12]);
void mazeTraversal(char *maze[12][12]);
static int face = 6;

main()
{
    int i = 0;
    int j = 0; 
    int k = 0;
    int start;
    int xpos;

    char *mazeone[12][12] = {
       //0///1///2///3///4///5///6///7///8///9///10//11///
        "#","#","#","#","#","#","#","#","#","#","#","#",//0
        "#",".",".",".","#",".",".",".",".",".",".","#",//1
        ".",".","#",".","#",".","#","#","#","#",".","#",//2
        "#","#","#",".","#",".",".",".",".","#",".","#",//3
        "#",".",".",".",".","#","#","#",".","#",".",".",//4
        "#","#","#","#",".","#",".","#",".","#",".","#",//5
        "#","#",".","#",".","#",".","#",".","#",".","#",//6
        "#","#",".","#",".","#",".","#",".","#",".","#",//7
        "#",".",".",".",".",".",".",".",".","#",".","#",//8
        "#","#","#","#","#","#",".","#","#","#",".","#",//9
        "#",".",".",".",".",".",".","#",".",".",".","#",//10
        "#","#","#","#","#","#","#","#","#","#","#","#",};//11

    for (i = 0; i <12; i++)
        if (mazeone[i][0] == "." ) {
            start = i; 
            mazeone[start][0] = "x";
            xpos = start;
            break;
        }

    printf("X is the starting point.\n");
    printf("Press Space Bar to watch the X move.\n\n\n");
    getchar();
    mazePrint(mazeone);
    getchar();
    return 0;
}

void mazePrint(char *maze[12][12])
{   
    int x = 0; 
    int y = 0;

    system("cls");
    for (x = 0; x < 12; x++) {
        for (y = 0; y < 12; y++) {
            printf("%s", maze[x][y]);
        }
        printf("\n"); 
    }
    getchar(); 
    mazeTraversal(maze);
}

void mazeTraversal(char *maze[12][12])
{
    int x = 0; 
    int y = 0;

    for (x = 0; x < 12; x++) {
        for (y = 0; y < 12; y++) {
            if (maze[y][x] == "x")
                break;
        } 
        if(maze[y][x] == "x")
            break;
    }

    for (y = 0; y < 12; y++) {
        for (x = 0; x < 12; x++) {
            if (maze[y][x] == "x")
                break;
        } 
        if (maze[y][x] == "x")
            break;
    }

    maze[y][x] = ".";

    switch (face) {
        case 6:{
            if (maze[y][x-1] == ".") {
                maze[y][x-1] = "x"; 
                face = 5;
            } else if (maze[y + 1][x] == ".") {
                maze[y + 1][x] = "x"; 
                face = 6;
            } else if (maze[y][x+1] == ".") {
                maze[y][x+1] = "x";
                face = 8;
            } else if (maze[y - 1][x] == ".") {
                maze[y - 1][x] = "x"; 
                face = 4;
            }
        }
        case 8:{
            if (maze[y + 1][x] == ".") {
                maze[y + 1][x] = "x"; 
                face = 6;
            } else if (maze[y][x+1] == ".") {
                maze[y][x+1] = "x";
                face = 8;
            } else if (maze[y - 1][x] == ".") {
                maze[y - 1][x] = "x"; 
                face = 4;
            } else if (maze[y][x-1] == ".") {
                maze[y][x-1] = "x"; 
                face = 5;
            }
        }
        case 4:{
            if (maze[y][x+1] == ".") {
                maze[y][x+1] = "x";
                face = 8;
            } else if (maze[y - 1][x] == ".") {
                maze[y - 1][x] = "x"; 
                face = 4;
            } else if (maze[y][x-1] == ".") {
                maze[y][x-1] = "x"; 
                face = 5;
            } else if (maze[y + 1][x] == ".") {
                maze[y + 1][x] = "x"; 
                face = 6;
            }
        }
        case 5:{
            if (maze[y - 1][x] == ".") {
                maze[y - 1][x] = "x";
                face = 4;
            } else if (maze[y][x-1] == ".") {
                maze[y][x-1] = "x"; 
                face = 5;
            } else if (maze[y + 1][x] == ".") {
                maze[y + 1][x] = "x"; 
                face = 6;
            } else if (maze[y][x+1] == ".") {
                maze[y][x+1] = "x";
                face = 8;
            }
        }
    }

    mazePrint(maze);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:46:59+00:00Added an answer on June 2, 2026 at 7:46 am

    You are missing the break; statements in the switch(face) after each case: block of code. Without the break; statements, your code will fall through to each of the next case:, which is not what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of -yes this IS a homework- but it's primarily a theoretical question rather
First question here, and yes this is a homework question. We are tasked with
this is my first question.. so, here we go. i have a site, 100%
This is my first question. I have an app in which i want to
Hello this is may first question and I have found so far the following
Yes, this is just a question i would like to get an answer on.
Yes, this is probably yet another greatest-n-per-group question... But I've tried at least a
Note 1: This is my first question here. Please be gentle. Note 2: Yes,
It has been a long question, so here is the summary first, I have
this is my first question on StackOverflow, but I think that we'll both come

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.