user8769: My program is a bit large and I'm worried about stability.
I need to print data to both a file and to my LCD. It's like this:
if (hour<10) {
    dataFile.print("0");
}
dataFile.print(hour, DEC);
dataFile.print(":");
if (minute<10) {
    dataFile.print("0");
}
dataFile.print(minute, DEC);
dataFile.print(":");
if (second<10) {
    dataFile.print("0");
}

Then 
if (hour<10) {
    lcd.print("0");
}
lcd.print(hour, DEC);
lcd.print(":");
if (minute<10) {
    lcd.print("0");
}
lcd.print(minute, DEC);
lcd.print(":");
if (second<10) {
    lcd.print("0");
}

What is a smart way to make this shorter? Should I write a function to add the leading zero then another that does something like:
void printboth (thing) {
    dataFile.print(thing);
    lcd.print(thing);
}

good idea?

user4143: You could format the data with snprintf:
char timestamp[9];
snprintf(timestamp, 9, "%02d:%02d:%02d", hour, minute, second);
dataFile.print(timestamp);
lcd.print(timestamp);

%02d in the snprintf format means "print at least 2 digits of this value and pad with leading zeros".

8769: <p>My program is a bit large and I'm worried about stability.</p>

<p>I need to print data to both a file and to my LCD. It's like this:</p>

<pre><code>if (hour&lt;10) {
    dataFile.print("0");
}
dataFile.print(hour, DEC);
dataFile.print(":");
if (minute&lt;10) {
    dataFile.print("0");
}
dataFile.print(minute, DEC);
dataFile.print(":");
if (second&lt;10) {
    dataFile.print("0");
}
</code></pre>

<p>Then </p>

<pre><code>if (hour&lt;10) {
    lcd.print("0");
}
lcd.print(hour, DEC);
lcd.print(":");
if (minute&lt;10) {
    lcd.print("0");
}
lcd.print(minute, DEC);
lcd.print(":");
if (second&lt;10) {
    lcd.print("0");
}
</code></pre>

<p>What is a smart way to make this shorter? Should I write a function to add the leading zero then another that does something like:</p>

<pre><code>void printboth (thing) {
    dataFile.print(thing);
    lcd.print(thing);
}
</code></pre>

<p>good idea?</p>
 4143: <p>You could format the data with snprintf:</p>

<pre><code>char timestamp[9];
snprintf(timestamp, 9, "%02d:%02d:%02d", hour, minute, second);
dataFile.print(timestamp);
lcd.print(timestamp);
</code></pre>

<p><code>%02d</code> in the snprintf <em>format</em> means "print at least 2 digits of this value and pad with leading zeros".</p>
