user48730: I use a LCD display to display a not known size of text ( changes over time ). I wish to display it at the center of LCD ( 2X16 ).
I declare:

  char t[16];
  char h[16];
  sprintf(t, "%.1f%cC %.0f%%", temperature,223, humidity);

Now, since I want to add additional data on a specific line and center it, I need to know it size. When using:
sizeof(t)/(sizeof(t[0])

I get 16 which is the size determined and not its actual size.
How can I get the exact number of chars used?

user4143: The function I think you are looking for is strlen - STRing LENgth.
It counts the number of characters in a string up until it finds the "NULL" end of string marker.
Serial.println(strlen(t));


48730: <p>I use a LCD display to display a not known size of text ( changes over time ). I wish to display it at the center of LCD ( 2X16 ).</p>

<p>I declare:
</p>

<pre class="lang-cpp prettyprint-override"><code>  char t[16];
  char h[16];
  sprintf(t, "%.1f%cC %.0f%%", temperature,223, humidity);
</code></pre>

<p>Now, since I want to add additional data on a specific line and center it, I need to know it size. When using:</p>

<pre class="lang-cpp prettyprint-override"><code>sizeof(t)/(sizeof(t[0])
</code></pre>

<p>I get <code>16</code> which is the size determined and not its actual size.</p>

<p>How can I get the exact number of chars <strong>used</strong>?</p>
 4143: <p>The function I think you are looking for is <code>strlen</code> - STRing LENgth.</p>

<p>It counts the number of characters in a string up until it finds the "NULL" end of string marker.</p>

<pre><code>Serial.println(strlen(t));
</code></pre>
