Realizzo un orologio con processore Arduino e, nel processo, sto cercando di formattare gli interi in stringhe formattate a due cifre per la lettura del tempo (ad esempio 1 in "01").Arduino String Formatting Edizione
Di seguito mi dà "Errore: atteso primaria espressione prima di '{' token":
char * formatTimeDigits (int num) {
char strOut[3] = "00";
if (num < 10) {
strOut = {'0', char(num)};
}
else {
strOut = char(num);
}
return strOut;
}
Sto cercando di usarlo come segue:
void serialOutput12() {
printWeekday(weekday); // picks the right word to print for the weekday
Serial.print(", "); // a comma after the weekday
Serial.print(hour12, DEC); // the hour, sent to the screen in decimal format
Serial.print(":"); // a colon between the hour and the minute
Serial.print(formatTimeDigits(minute)); // the minute
Serial.print(":"); // a colon between the minute and the second
Serial.print(formatTimeDigits(second)); // the second
}
Tutte le idee su cosa mi manca qui?
Ok grazie! Essendo abituato a C#, immagino di aver pensato che avrebbe passato un riferimento alla funzione (eek). – amb9800
It (il vostro esempio originale) * fa * restituisce un riferimento, ma ad un oggetto che cessa di esistere dopo che la funzione è stata chiusa (quindi diventa un riferimento ciondolante). C non ha un conteggio di riferimento incorporato/garbage-collection. – caf