How to search different dimensions of the same array? - page 2

 

Still theres gotta be a way to assign a value to a specific dimension in the example

I greatly value and appreciate your suggestions.

 
void OnStart()
  {
//---
   ulong arr[2][3][4][2];
   ulong i=1;
   for(int j=0;j<2;j++)
      for(int k=0;k<3;k++)
         for(int l=0;l<4;l++)
            for(int m=0;m<2;m++)
               arr[j][k][l][m]=i<<=1;

   for(int j=0;j<2;j++)
      for(int k=0;k<3;k++)
         for(int l=0;l<4;l++)
            for(int m=0;m<2;m++)
              { 
               printf("array[%i,%i,%i,%i]=%I64u",j,k,l,m,arr[j,k,l,m]);
               Sleep(10);
              }

   if(ArrayFind(arr,4194304))
      Print("Value found!");

  }
 
Ernst Van Der Merwe:
This is a little too cryptic for my level. Mind an explanation?
 
template<typename T1,typename T2>
bool ArrayFind(const T1 &array[][][][],const T2 value)
  {
   int size[4]={0};
   for(int i=0;i<4;i++)
      size[i]=ArrayRange(array,i);
   for(int i=0;i<size[0];i++)
      for(int j=0;j<size[1];j++)
         for(int k=0;k<size[2];k++)
            for(int l=0;l<size[3];l++)
               if(array[i][j][k][l]==(T1)value)
                  return(true);
   return(false);
  }

Your original code needs changing then as you've changed the dimensions?

Should now be

template<typename T1,typename T2>
bool ArrayFind(const T1 &array[][][][],const T2 value)
  {
   int size[4]={0};
   for(int i=0;i<4;i++)
      size[i]=ArrayRange(array,i);
   for(int j=0;i<size[2];i++)
      for(int k=0;j<size[3];j++)
         for(int l=0;k<size[4];k++)
            for(int m=0;l<size[2];l++)
               if(array[j][k][l][m]==(T1)value)
                  return(true);
   return(false);
  }

?

Appreciate your help, this is extremely difficult.

 

How to specify in what specific dimension to store a value?

Not enough info online.

Reason: