<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>al_ref_ustr start and end effect</title>
		<link>http://www.allegro.cc/forums/view/618666</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 21 May 2022 17:49:26 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m a bit lost on how <tt>al_ref_ustr</tt> is supposed to work.<br />If it specifies an end point, I assume it&#39;s meant to only return chars until the specified end, right?</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><a href="http://www.allegro.cc/manual/ALLEGRO_USTR"><span class="a">ALLEGRO_USTR</span></a> <span class="k3">*</span>text_typed <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_ustr_new"><span class="a">al_ustr_new</span></a><span class="k2">(</span><span class="s">"1234567890"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  2</span><a href="http://www.allegro.cc/manual/ALLEGRO_USTR_INFO"><span class="a">ALLEGRO_USTR_INFO</span></a> text_info<span class="k2">;</span>
<span class="number">  3</span>
<span class="number">  4</span><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span>
<span class="number">  5</span><span class="k2">{</span>
<span class="number">  6</span>    <a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  7</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Char: %s \n"</span>,<a href="http://www.allegro.cc/manual/al_cstr"><span class="a">al_cstr</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_ref_ustr"><span class="a">al_ref_ustr</span></a><span class="k2">(</span><span class="k3">&amp;</span>text_info, text_typed, <a href="http://www.allegro.cc/manual/al_ustr_offset"><span class="a">al_ustr_offset</span></a><span class="k2">(</span>text_typed,<span class="n">2</span><span class="k2">)</span>, <a href="http://www.allegro.cc/manual/al_ustr_offset"><span class="a">al_ustr_offset</span></a><span class="k2">(</span>text_typed,<span class="n">4</span><span class="k2">)</span><span class="k2">)</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>    <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number">  9</span><span class="k2">}</span>
</div></div><p>

I expected:<br /><tt>Char: 34</tt><br />I got:<br /><tt>Char: 34567890</tt></p><p>If this isn&#39;t the case, which function should I use instead then?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (TylerD)</author>
		<pubDate>Thu, 19 May 2022 08:19:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Your <span class="source-code"><a href="http://www.allegro.cc/manual/al_ref_ustr"><span class="a">al_ref_ustr</span></a></span> is fine, the problem is that you can&#39;t always convert a ustr to a cstr just with <span class="source-code"><a href="http://www.allegro.cc/manual/al_cstr"><span class="a">al_cstr</span></a></span>. The reason is that <span class="source-code"><a href="http://www.allegro.cc/manual/al_ref_ustr"><span class="a">al_ref_ustr</span></a></span> has to create a substring from <span class="source-code">text_typed</span> without altering <span class="source-code">text_typed</span>, but a cstr is only a pointer to char, and the only way to figure out its length is to scan for the <span class="source-code">\<span class="n">0</span></span>. So <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a></span> just runs past the end until it hits the end of the underlying string in <span class="source-code">text_typed</span>.</p><p>You&#39;d have to use <span class="source-code"><a href="http://www.allegro.cc/manual/al_ustr_to_buffer"><span class="a">al_ustr_to_buffer</span></a></span> if you wanted a &#39;stand-alone&#39; C string, which makes the whole substring thing a bit pointless maybe.</p><p>Obviously if you stick to ustr functions then the string made by <span class="source-code"><a href="http://www.allegro.cc/manual/al_ref_ustr"><span class="a">al_ref_ustr</span></a></span> would work perfectly.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Hull)</author>
		<pubDate>Thu, 19 May 2022 10:52:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That helped. I was using printf for troubleshooting in the original code, however. In the end, I wrote a very different code for external reasons though.<br />Thanks anyway!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (TylerD)</author>
		<pubDate>Sat, 21 May 2022 17:49:26 +0000</pubDate>
	</item>
</rss>
