I'm currently programming a robot to navigate around a factory for uni using C++ but being an Engineer and not a programmer I dont really know much about C++. I've written a function called routefinder that is passed in the startx,startx,desiredx,desiredy cordinates. The program uses global variables which contain the location of objects around the factory. The function is to return the number of turning points and also output these turning points to a global array. How do I tell the function to output the points to a global array as it goes along?
Bellow is a little snippet of code, in bold are the two arrays I would like to be accessable outside the function.
int RouteFinder1(int Start_X,int Start_Y,int Desired_X,int Desired_Y)
{ //Subroutine Start
int Pillar1_X,Pillar1_Y,Pillar2_X,Pillar2_Y,Pillar3_X,Pillar3_Y,Pillar4_X,Pillar4_Y;
int flag = 0, NavPointCounter = 0,Current_X,Current_Y;
Current_X = Start_X;
Current_Y = Start_Y;
/* Up Then Right /*
/**************************************************************/
if (Desired_X > Start_X && Desired_Y > Start_Y)
{ //Open main loop 1
while (Current_Y < Desired_Y)
{ //Loop1
Current_Y ++;
flag == 0;
if (Current_Y == Desired_Y)
{
NavPointsX[NavPointCounter] = Current_X;
NavPointsY[NavPointCounter] = Current_Y;
NavPointCounter++;
}
Bellow is a little snippet of code, in bold are the two arrays I would like to be accessable outside the function.
int RouteFinder1(int Start_X,int Start_Y,int Desired_X,int Desired_Y)
{ //Subroutine Start
int Pillar1_X,Pillar1_Y,Pillar2_X,Pillar2_Y,Pillar3_X,Pillar3_Y,Pillar4_X,Pillar4_Y;
int flag = 0, NavPointCounter = 0,Current_X,Current_Y;
Current_X = Start_X;
Current_Y = Start_Y;
/* Up Then Right /*
/**************************************************************/
if (Desired_X > Start_X && Desired_Y > Start_Y)
{ //Open main loop 1
while (Current_Y < Desired_Y)
{ //Loop1
Current_Y ++;
flag == 0;
if (Current_Y == Desired_Y)
{
NavPointsX[NavPointCounter] = Current_X;
NavPointsY[NavPointCounter] = Current_Y;
NavPointCounter++;
}