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

  • SEARCH
  • Home
  • 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 8925585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:44:17+00:00 2026-06-15T07:44:17+00:00

I have what I consider a really strange problem. I have a function with

  • 0

I have what I consider a really strange problem. I have a function with the following prototype:

void generateNodes(const int maxX, const int maxY, node nodes[]);

As one of the first things in this function I define a 2d array of shorts, which i use as boolean values. But when I call this function the value of maxY changes to a large value. The code in question is below:

void generateNodes(const int maxX, const int maxY, node nodes[]){
    int i, currentX, currentY;

    short used[MAX_NODES][MAX_NODES];

    //Generate the nodes
    for(i = 0; i < MAX_NODES; i++){
        currentX = randomNumber(0,maxX);
        currentY = randomNumber(0,maxY);

        nodes[i].color = 0;
        nodes[i].numberOfConnections = 0;
        nodes[i].id = i;
        nodes[i].distanceFromStart = NOT_SET;
        nodes[i].parent = NULL;

        if(!used[currentX][currentY]){
            nodes[i].x = currentX;
            nodes[i].y = currentY;

            used[currentX][currentY] = 1;
        } else {
            i--;
        }
    }

    int numberOfConnections, j, currentNeighbor;

    //Generate the connections
    for(i = 0; i < MAX_NODES; i++){
        numberOfConnections = randomNumber(1,5); //Between one and five outgoing connections

        for(j = 0; j < numberOfConnections; j++){

            currentNeighbor = randomNumber(0,19); //Select the neighbor

            while(currentNeighbor == i){
                currentNeighbor = randomNumber(0,19); //Try again while the selected is self
            }

            nodes[i].canReach[++(nodes[i].numberOfConnections)] = &nodes[currentNeighbor];

            nodes[currentNeighbor].canReach[++(nodes[currentNeighbor].numberOfConnections)] = &nodes[i];
        }
    } 
}

MAX_NODES is defined to 20.

Does anyone know why this might happen?

  • 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-15T07:44:21+00:00Added an answer on June 15, 2026 at 7:44 am

    Since you do not seem to initialize the array used, it may well be that some elements are considered used (!= 0), since an array on stack is not initialized to zero, but takes whatever was in that memory area before.
    An if an X,Y pair is considered used, you decrement the loop counter, possibly beyond zero into the negative realm, possibly overwriting – on the next iteration – part of the stack. This may also change the parameters, since they also reside on the same stack, before the local array.

    Start with initializing used, and consider rewriting the loop to not change the loop variable except in the for statement.

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

Sidebar

Related Questions

Consider I have the following interface: public interface A { public void b(); }
I have encountered a slightly unusual problem. Consider the following code: class parser {
Before Consider to have a class and a global function: This is, for example,
Consider we have a simple cycling Javascript process as: function test() { el=document.getElementById("test"); var
Consider I have a shared function:- Public Shared Function CalculateAreaFromRadius(ByVal radius As Double) As
I'm working on my compiler homework and I have the following question: Consider the
I really don't consider myself a java or tomcat expert. I have a vps
I have a problem that I really need solved in any way (changing data
Consider the really simple code below: #include <stdio.h> #include <stdlib.h> int main() { int*
Lets consider I have a class inside a really long module path: sux =

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.