i’ve been working in C# and have totally forgotten how to use pointers (to my chagrin … and frustration)
i’m passing an array of pointers of bytes to a function and the receiving function does not know their values.
here’s a code sample
String getString_WorkOut_Time(byte *bytTime[3])
{
String strHours = String(*bytTime[0]);
while (strHours.length() < 2)
strHours = "0" + strHours;
String strMinutes = String(*bytTime [1]);
while (strMinutes.length() < 2)
strMinutes = "0" + strMinutes;
String strSeconds = String(*bytTime[2]);
while (strSeconds.length() < 2)
strSeconds = "0" + strSeconds;
// /*
Serial.print(F("EditWorkOut_Time_Draw() "));
Serial.print(strHours);
Serial.print(F(":"));
Serial.print(strMinutes);
Serial.print(F(":"));
Serial.println(strSeconds);
// */
String strTime = strHours + ":" + strMinutes + ":" + strSeconds;
return strTime;
}
bool EditWorkOut_Time()
{
Serial.print(F("EditWorkOut_Time()-> before call:"));
Serial.print(String(cWorkout.bytTimer_Hours));
Serial.print(F(":"));
Serial.print(String(cWorkout.bytTimer_Minutes));
Serial.print(F(":"));
Serial.println(String(cWorkout.bytTimer_Seconds));
int intRange[] = {99, 60, 60};
byte *bytTime[3] = { cWorkout.bytTimer_Hours, cWorkout.bytTimer_Minutes, cWorkout.bytTimer_Seconds};
getString_WorkOut_Time(bytTime);
Serial.print(F("EditWorkOut_Time()-> after call :"));
Serial.print(String(cWorkout.bytTimer_Hours));
Serial.print(F(":"));
Serial.print(String(cWorkout.bytTimer_Minutes));
Serial.print(F(":"));
Serial.println(String(cWorkout.bytTimer_Seconds));
return;
}
the results on my Serial port are
EditWorkOut_Time()-> before call:1:30:12
Hours before adding 0s000Hours after adding 0s
EditWorkOut_Time_Draw() 00:30:00
EditWorkOut_Time()-> after call :1:30:12
clearly the values of h:m:s being sent are 1:30:12
but the receiving function thinks they’re 0:30:00 ?!?
the example I’m following is from C - Array of pointers - Tutorialspoint
even though the example is not passing the pointers am i not using them the same way?
Live Demo
#include <stdio.h>
const int MAX = 3;
int main () {
int var[] = {10, 100, 200};
int i, *ptr[MAX];
for ( i = 0; i < MAX; i++) {
ptr[i] = &var[i]; /* assign the address of integer. */
}
for ( i = 0; i < MAX; i++) {
printf("Value of var[%d] = %d\n", i, *ptr[i] );
}
return 0;
}