Go Down

Topic: Char - Bidimensional Array pass to function (Read 315 times) previous topic - next topic

gnusso

Good Morning,
I've have the following array of char :
Code: [Select]
byte array [31] [31];

and I need to pass to my function :
Code: [Select]
void LeggiArray(byte YearStart, byte MonthStart,byte DayStart,byte HourStart,byte MinStart, byte YearStop,byte MonthStop,byte DayStop,byte HourStop, byte MinStop)
{
  char dataNow[11];
  char dataArrayStart[11];
  char dataArrayStop[11];
   
  time_t t = now();
  for (int i = 0; i <=  devices ; i++)
    {
     sprintf(dataNow, "%04d%02d%02d%02d%02d", year(t), month(t), day(t), hour(t), minute(t));
     sprintf(dataArrayStart, "%04d%02d%02d%02d%02d", (YearStart + 2000),  MonthStart, DayStart, HourStart, MinStart);
     sprintf(dataArrayStop,  "%04d%02d%02d%02d%02d", (YearStop  + 2000),  MonthStop,  DayStop,  HourStop,  MinStop);
     
     if (strcmp(dataNow,dataArrayStart) >= 0 && strcmp(dataNow,dataArrayStop) <= 0)
         {
           if (array[i][12] == 0)
            {
              // array[i][12] = 32 ;
              Serial.println("Turn On");
            }
           else
             if (array[i][12] == 32)
              {
               // array[i][12] = 0;
               Serial.println("Turn Off");
              }
         }   
      } 
}


Then I call my function in this way:

Code: [Select]
LeggiArray(array[0][6],array[0][5],array[0][4],array[0][2],array[0][3],array[0][11],array[0][10],array[0][9],array[0][7],array[0][8]);

But I would like call My Function with roms and colums like parameter ...
is correct this the correct way ?

Thanks
Gnux

pylon

I understand what you have but your desires are less clear. Show us what you want to have.

gnusso

Ok thanks so mainly I have the function below reported ... where I use a for cycles for scan my timer ... Since the moment that "the logical part" of timer is always the same for the different my situation to re-use this procedure with different date start hour start min start  and different date stop hour stop min . Then my parameter are contained inside a array of byte with 2 dimension ...

Code: [Select]

void LeggiArray()
{
 
  for (int i = 0; i <=  devices ; i++)
    {
     char dataNow[15];
     char dataArrayStart[15];
     char dataArrayStop[15];
     time_t t = now();
     sprintf(dataNow, "%04d%02d%02d%02d%02d", year(t), month(t), day(t), hour(t), minute(t));
     // Serial.println(dataNow);
     sprintf(dataArrayStart, "%04d%02d%02d%02d%02d", (array[i][6]+2000), array[i][5], array[i][4], array[i][2], array[i][3]);
     // Serial.println(dataArrayStart);
     sprintf(dataArrayStop, "%04d%02d%02d%02d%02d", (array[i][11]+2000), array[i][10], array[i][9], array[i][7], array[i][8]);
     
     if (strcmp(dataNow,dataArrayStart) >= 0 && strcmp(dataNow,dataArrayStop) <= 0)
       {
         if (array[i][12] == 0)
          {
            array[i][12] = 32 ;
            Serial.println("Turn On");
          }
         else
           if (array[i][12] == 32)
            {
             array[i][12] = 0;
             Serial.println("Turn Off");
            }
       }

      } 



Let me know if you want more details thanks you for the support,
have nice day
gnux

pylon

I don't understand your description but from your code I guess you're looking for this function definition:

Code: [Select]
void LeggiArray(byte **array)

An array is a pointer to the content, an array of arrays is a pointer to pointers to the content.

Go Up