user31185: How to format an integer as 3 digit string? If I give 3 formated string should be 003
printf("%03d\n", 3); // output: 003 

This doesn't work in Arduino.

user-1: The standard C function printf print to stdout. Arduino doesn't has a stdout. You can print to Serial, but must prepare/format the string first.
Instead of printf, use snprintf. It prints to a char array, which you later can use with Serial.print, or whatever other function that take a string.
void setup() {
  Serial.begin(9600);
  while(!Serial);

  char buffer[4];
  snprintf(buffer,sizeof(buffer), "%03d", 3);
  Serial.println(buffer);
}

void loop() {

}

Note: all the comments apply to this answers.

31185: <p>How to format an integer as 3 digit string? If I give <code>3</code> formated string should be <code>003</code></p>

<pre><code>printf("%03d\n", 3); // output: 003 
</code></pre>

<p>This doesn't work in Arduino.</p>
 -1: <p>The standard C function <code>printf</code> print to stdout. Arduino doesn't has a stdout. You can print to Serial, but must prepare/format the string first.</p>

<p>Instead of <code>printf</code>, use <code>snprintf</code>. It prints to a char array, which you later can use with <code>Serial.print</code>, or whatever other function that take a string.</p>

<pre><code>void setup() {
  Serial.begin(9600);
  while(!Serial);

  char buffer[4];
  snprintf(buffer,sizeof(buffer), "%03d", 3);
  Serial.println(buffer);
}

void loop() {

}
</code></pre>

<p>Note: all the comments apply to this answers.</p>
