<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[RemoteXY community — prefix a leading zero to a char variable]]></title>
	<link rel="self" href="https://forum.remotexy.com/extern.php?action=feed&amp;tid=1529&amp;type=atom" />
	<updated>2022-08-18T12:30:33Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.remotexy.com/viewtopic.php?id=1529</id>
		<entry>
			<title type="html"><![CDATA[Re: prefix a leading zero to a char variable]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=4770#p4770" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>remotexy wrote:</cite><blockquote><div class="codebox"><pre><code>struct {
    // output variables
  char minutes_run[4];  // string UTF8 end zero 
  char seconds_run[4];  // string UTF8 end zero 
} RemoteXY;

sprintf (RemoteXY.minutes_run, &quot;%02d&quot;, minutes_run);
sprintf (RemoteXY.seconds_run, &quot;%02d&quot;, seconds_run);</code></pre></div><p>minutes_run and seconds_run is a text string</p></blockquote></div><p>Thank you : working well ....</p>]]></content>
			<author>
				<name><![CDATA[Daba]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=630</uri>
			</author>
			<updated>2022-08-18T12:30:33Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=4770#p4770</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: prefix a leading zero to a char variable]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=4769#p4769" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>struct {
    // output variables
  char minutes_run[4];  // string UTF8 end zero 
  char seconds_run[4];  // string UTF8 end zero 
} RemoteXY;

sprintf (RemoteXY.minutes_run, &quot;%02d&quot;, minutes_run);
sprintf (RemoteXY.seconds_run, &quot;%02d&quot;, seconds_run);</code></pre></div><p>minutes_run and seconds_run is a text string</p>]]></content>
			<author>
				<name><![CDATA[remotexy]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=2</uri>
			</author>
			<updated>2022-08-18T08:27:25Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=4769#p4769</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: prefix a leading zero to a char variable]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=4767#p4767" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>remotexy wrote:</cite><blockquote><p>For example<br /></p><div class="codebox"><pre><code>  void writeTime () {
    uint32_t d = millis();
    long ds = d/1000;
    long dm = d%1000;
    char s[15];
    sprintf (s, &quot;[%5ld.%03ld] &quot;,ds, dm);       
    serial-&gt;println ();    
    serial-&gt;print (s);
  }</code></pre></div></blockquote></div><p>Very good, but that doesn&#039;t help me to add leading zeroes to the RemoteXY structure members of my original post ...</p><p>To be honest, I get confused between char[] and string variables, and when to use, and when not to use, I guess I need to watch some good tutorials...</p>]]></content>
			<author>
				<name><![CDATA[Daba]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=630</uri>
			</author>
			<updated>2022-08-15T22:29:44Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=4767#p4767</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: prefix a leading zero to a char variable]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=4765#p4765" />
			<content type="html"><![CDATA[<p>For example<br /></p><div class="codebox"><pre><code>  void writeTime () {
    uint32_t d = millis();
    long ds = d/1000;
    long dm = d%1000;
    char s[15];
    sprintf (s, &quot;[%5ld.%03ld] &quot;,ds, dm);       
    serial-&gt;println ();    
    serial-&gt;print (s);
  }</code></pre></div>]]></content>
			<author>
				<name><![CDATA[remotexy]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=2</uri>
			</author>
			<updated>2022-08-15T18:57:55Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=4765#p4765</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: prefix a leading zero to a char variable]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=4762#p4762" />
			<content type="html"><![CDATA[<p>I suppose I should have said char[] array variable, rather than just a single char.</p><p>But never mind, I&#039;ve decided to not display the seconds and minutes of my run_time, just the hours, so the problem (for now) has gone away.</p><p>I&#039;m certain I&#039;ll be able to figure it out if I need to do it in the future, but it would sure be nice if there was a time display library, not found one yet.</p>]]></content>
			<author>
				<name><![CDATA[Daba]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=630</uri>
			</author>
			<updated>2022-08-13T20:30:58Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=4762#p4762</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[prefix a leading zero to a char variable]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=4761#p4761" />
			<content type="html"><![CDATA[<p>I want to display the following data with a leading zero if the value is less than 10.</p><div class="codebox"><pre><code>  value = minutes_run; 
  dtostrf(value, 2, 0, RemoteXY.minutes_run);  
  value = seconds_run; 
  dtostrf(value, 2, 0, RemoteXY.seconds_run);  </code></pre></div><p>I&#039;m having a mind-melt on how best to do it, I know it should be straightforward enough surely ...</p><p>Can anyone help, I&#039;m running out of time on this project ....</p>]]></content>
			<author>
				<name><![CDATA[Daba]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=630</uri>
			</author>
			<updated>2022-08-12T14:26:25Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=4761#p4761</id>
		</entry>
</feed>
