我正在制作一个由 Arduino 驱动的时钟,在此过程中,我试图将整数格式化为两位数格式的字符串,以便读取时间(例如,将 1 转换为“01”)。
以下给了我“错误:'{'令牌之前的预期主表达式”:
char * formatTimeDigits (int num) {
char strOut[3] = "00";
if (num < 10) {
strOut = {'0', char(num)};
}
else {
strOut = char(num);
}
return strOut;
}
我正在尝试按如下方式使用它:
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
}
关于我在这里缺少什么的任何想法?