<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>al_fwrite and 26.</title>
		<link>http://www.allegro.cc/forums/view/606718</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 16 Mar 2011 03:55:25 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><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><span class="p">#include "allegro5/allegro.h"</span>
<span class="number">  2</span><span class="p">#include &lt;iostream&gt;</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.allegro.cc/manual/ALLEGRO_FILE"><span class="a">ALLEGRO_FILE</span></a><span class="k3">*</span> file<span class="k2">;</span>
<span class="number">  8</span>
<span class="number">  9</span>  file <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_fopen"><span class="a">al_fopen</span></a><span class="k2">(</span><span class="s">"test"</span>, <span class="s">"w"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span>  <a href="http://www.allegro.cc/manual/al_fwrite32le"><span class="a">al_fwrite32le</span></a><span class="k2">(</span>file, <span class="n">26</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>  <a href="http://www.allegro.cc/manual/al_fclose"><span class="a">al_fclose</span></a><span class="k2">(</span>file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span>
<span class="number"> 13</span>  file <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_fopen"><span class="a">al_fopen</span></a><span class="k2">(</span><span class="s">"test"</span>, <span class="s">"r"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>  std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <a href="http://www.allegro.cc/manual/al_fread32le"><span class="a">al_fread32le</span></a><span class="k2">(</span>file<span class="k2">)</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span>
<span class="number"> 15</span>  <a href="http://www.allegro.cc/manual/al_fclose"><span class="a">al_fclose</span></a><span class="k2">(</span>file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span>
<span class="number"> 17</span>  file <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_fopen"><span class="a">al_fopen</span></a><span class="k2">(</span><span class="s">"test"</span>, <span class="s">"w"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 18</span>  <a href="http://www.allegro.cc/manual/al_fwrite32le"><span class="a">al_fwrite32le</span></a><span class="k2">(</span>file, <span class="n">27</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>  <a href="http://www.allegro.cc/manual/al_fclose"><span class="a">al_fclose</span></a><span class="k2">(</span>file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 20</span>
<span class="number"> 21</span>  file <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_fopen"><span class="a">al_fopen</span></a><span class="k2">(</span><span class="s">"test"</span>, <span class="s">"r"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>  std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <a href="http://www.allegro.cc/manual/al_fread32le"><span class="a">al_fread32le</span></a><span class="k2">(</span>file<span class="k2">)</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span>
<span class="number"> 23</span>  <a href="http://www.allegro.cc/manual/al_fclose"><span class="a">al_fclose</span></a><span class="k2">(</span>file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 24</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_802.html" target="_blank">system</a><span class="k2">(</span><span class="s">"pause"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 25</span>
<span class="number"> 26</span>
<span class="number"> 27</span>  <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 28</span><span class="k2">}</span>
</div></div><p>

This is what I get from the console:</p><p>-1<br />27<br />Press any key to continue ...</p><p>I don&#39;t wana scream bug, but this seems kind of fishy.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jason perkins)</author>
		<pubDate>Tue, 15 Mar 2011 18:59:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Try using &quot;wb&quot; and &quot;rb&quot; instead of &quot;w&quot; and &quot;r&quot;.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 15 Mar 2011 19:06:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606718/907955#target">Elias</a> said:</div><div class="quote"><p> Try using &quot;wb&quot; and &quot;rb&quot; instead of &quot;w&quot; and &quot;r&quot;.</p></div></div><p>I tested it and yes, that was the problem.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Tue, 15 Mar 2011 19:08:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I wonder if Allegro should do that for you. I&#39;m never using Windows but still always use &quot;wb&quot; and &quot;rb&quot; since I know that Windows will possibly garble every byte &lt;= ascii 32 otherwise. But for the Allegro file operations we could just specify that they are always in binary mode and fix the windows drivers accordingly. I can&#39;t see any problems with that, unless someone knows of an actual use for the standard libc behavior with &quot;w&quot; and &quot;r&quot;.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 15 Mar 2011 19:13:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks alot, You wouldn&#39;t believe how long I&#39;ve spent trying to figure out my problem.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jason perkins)</author>
		<pubDate>Tue, 15 Mar 2011 19:22:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> But for the Allegro file operations we could just specify that they are always in binary mode and fix the windows drivers accordingly. I can&#39;t see any problems with that, unless someone knows of an actual use for the standard libc behavior with &quot;w&quot; and &quot;r&quot;.</p></div></div><p>That would also keep things the same as the File I/O routines in A4, which also doesn&#39;t differentiate between text and binary mode.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Tue, 15 Mar 2011 19:24:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>As far as I understand it, it&#39;s standard C behaviour : A portable piece of code that writes &quot;ABC\nDEF&quot; as a text file should read back &quot;ABC\nDEF&quot;.</p><p>(This is an answer to &quot;an actual use for the standard libc behavior with &quot;w&quot; and &quot;r&quot;.&quot;)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Tue, 15 Mar 2011 19:29:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606718/907962#target">Audric</a> said:</div><div class="quote"><p>As far as I understand it, it&#39;s standard C behaviour : A portable piece of code that writes &quot;ABC\nDEF&quot; as a text file should read back &quot;ABC\nDEF&quot;.</p></div></div><p>

Unfortunately not. Only if you use &quot;rb&quot; and &quot;wb&quot; in fopen. [edit:] Otherwise it only applies for ASCII files and if you don&#39;t care that line endings get mangled on disk.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 15 Mar 2011 19:56:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>My meaning was for portable C code that reads and writes in text file: The code opens the file in TEXT mode, fwrite() the single &#39;\n&#39; character, and the libc implementation will do whatever is required to produce a Newline character on the platform. Similarly, open back the file in TEXT mode, fread(), and you should get the single &#39;\n&#39; character.<br />This is straight-from-the-book implementation of the C standard... And it means the same piece of source code will produce similar-behaving programs on platforms that handle text files differently at the byte level.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Tue, 15 Mar 2011 21:16:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606718/907989#target">Audric</a> said:</div><div class="quote"><p>and the libc implementation will do whatever is required to produce a Newline character on the platform</p></div></div><p>

Yes. And Allegro 5 works like that as well now. I think it would be better if it didn&#39;t.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 15 Mar 2011 22:15:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>For future reference, I just remembered: character 26 is <a href="http://en.wikipedia.org/wiki/Control-Z">ctrl-z</a>, so it marks end-of-file. When you read a file in text mode, encountering this character should stop the reading as if the physical end-of-file was reached, it explains the &quot;-1&quot; returned by al_fread32le().</p><p>I remember some file formats used this trick, they started by a human-readable string,then ctrl-z, then the binary data started. Opening such file in a basic text editor should only show the string - though nowadays many programmer&#39;s editors can show the hidden content.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Wed, 16 Mar 2011 03:55:25 +0000</pubDate>
	</item>
</rss>
