Closed pierrebressy closed 2 years ago
counter = 1-counter; // 0, 1, 0, 1 etc.
counter++;
in the loop function:
if(counter&1) { display_temp(); }
else { display_humidity(); }
void displayTemp() {
puts("T=xxx °C");
return;
}
void displayHumidity() {
puts("H=XXX %");
return;
}
int main(int argc, char const *argv[])
{
void (*functions[2])(void) = {displayTemp,displayHumidity};
int counter = 0;
for (counter = 0; counter < 5;counter++) {
functions[counter&1]();
}
return 0;
}
void displayTemp() { puts("T=xxx °C"); return; } void displayHumidity() { puts("H=XXX %"); return; } int main(int argc, char const *argv[]) { void (*functions[2])(void) = {displayTemp,displayHumidity}; int counter = 0; for (counter = 0; counter < 5;counter++) { functions[counter&1](); } return 0; }
Used this solution
option 1 :
counter = 1-counter; // 0, 1, 0, 1 etc.
option 2 :
counter++;
in the loop function:
if(counter&1) { display_temp(); } else { display_humidity(); }