私はArduino電源の時計を作っていますが、その過程で、整数を2桁のフォーマットされた文字列に変換しようとしています(例えば、 "01"に1)。Arduino String Formatting問題
以下は私に「エラー: 『{』トークン前に、プライマリ・表現予想」:与え、私は次のようにそれを使用しようとしている
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
}
任意のアイデアをするようここで私は何が欠けているのですか?
ありがとう! C#に慣れているので、関数(eek)への参照を渡すと仮定していたと思います。 – amb9800
(あなたのorignalの例)*は*参照を返しますが、関数が終了した後に存在しなくなったオブジェクトに参照を返します(したがって、参照がぶら下がります)。 Cには参照カウント/ガベージコレクションが組み込まれていません。 – caf