-2

I'm programming in C and I need some help: I' have a bidimensional vector ( n rows, 2 columns) and each rows represent the coordinates of an Element I want to put in a bigger bidimensional vector, something like battleship. Is it possible to give a name to each rows? For example, how can I give the name X to the first element of my smaller vector?

What I've to do is: the element in vector represents coordinate of an element in a bigger vector, so each rows represent an element. I compare to at once, and if their are neighbors and one of them is "X", also the other one become an "X" element. Something like that:

enter code here
int x,y;
for(int a=0; a<nbE; a++)                         
   {    
    for(int i=1; i<n;i++)                      
       {
           x=vector[a][0]-vector[i][0];

                   if((x==1)||(x==-1)||(x==0))
          {
            y=vector[a][1]-vector[i][1];

            if( (y==1)||(y==-1)||(y==0))
              { 
                if (vector[a]="X")             *That's the point*
                   vector[i]="X";
              }  
          }     
       }          
   .......
   }
Maile2597
  • 1
  • 1

1 Answers1

0

In C this is not directly possible, however.

A tricky (thus not recommended) approach does exist:

#define X (vector[0][0])

Now you're able to use X anywhere to resemble vector[0][0].

If you migrate your project to C++ then reference will be available, providing a natural way to do so.

iBug
  • 35,554
  • 7
  • 89
  • 134