Pages: [1]   Go Down
Author Topic: Char - Bidimensional Array pass to function  (Read 253 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 2
Posts: 407
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

and I need to pass to my function :
Code:
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:
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
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4702
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Sr. Member
****
Karma: 2
Posts: 407
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4702
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
void LeggiArray(byte **array)

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

Pages: [1]   Go Up
Jump to: