Hi, i'm trying to implement an algorithm using multidimensional arrays (matrices), structs and nested for loops. i would like to scan the matrix continously in order to manipulate the variables assigned to the struct members. I added an outer for loop to do this but it doesn't seem to work. any suggestions on how i might do this will be appreciated. portion of code is listed below:
/* This program creates a multidimension matrix representing a
2D array of nodes. Each array element represents a coordinate
in the 2D space. values of array elements signify node IDs
with the array elements being their coordinates.value's zero of the
array elements signify no nodes - just space.
The program attempts to implement an algorithm that scans the matrix
to gather node positions(coordinates)
*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
//define structure
struct coord {
int x;
int y;
int xfirsthopneighbour;
int xsecondhopneighbour;
int active;
int anchornodestatus;
};
//declare and initialize array matrix
int array[4][4] = {{0,0,0,2},{0,1,0,0},{0,5,3,0},{4,0,0,0}};
// function prototype and global variable define
int performaveraging(struct coord *t);
int a,b;
int i = 20;
int main()
{
struct coord node[5];
node[0].x = 0;
node[0].active = 0;
node[0].xfirsthopneighbour = 5;
node[0].xsecondhopneighbour = 3;
node[0].anchornodestatus = 0;
node[1].x = 3;
node[1].active = 1;
node[1].xfirsthopneighbour = 1;
node[1].xsecondhopneighbour = 3;
node[1].anchornodestatus = 1;
node[2].x = 0;
node[2].active = 0;
node[2].xfirsthopneighbour = 2;
node[2].xsecondhopneighbour = 1;
node[2].anchornodestatus = 0;
node[3].x = 0;
node[3].active = 1;
node[3].xfirsthopneighbour = 5;
node[3].xsecondhopneighbour = 1;
node[3].anchornodestatus = 1;
node[4].x = 0;
node[4].active = 0;
node[4].xfirsthopneighbour = 4;
node[4].xsecondhopneighbour = 1;
node[4].anchornodestatus = 0;
for(i=0;i<20;i++) //this loop is my concern
{
for(a=0;a<4;a++)
{
for(b=0;b<4;b++)
{
if((array[a][b]) != 0)
{
// if neighbour is anchor or active acquire and store its coordinates
if(node[(node[array[a][b]-1].xfirsthopneighbour)-1].anchornodestatus == 1 ||
node[(node[array[a][b]-1].xfirsthopneighbour)-1].active == 1 &&
node[array[a][b]-1].active == 0)
{
node[array[a][b]-1].x = node[(node[array[a][b]-1].xfirsthopneighbour)-1].x;
node[array[a][b]-1].active = 1;
}
}
}
return 0;
}
return 0;
}