<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>File I/O</title>
		<link>http://www.allegro.cc/forums/view/613391</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 23 Oct 2013 21:10:52 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I couldn&#39;t figure out how to solve these problems:</p><p>1. Getting values from a text file with fscanf, resetting file content, then writing down the new values using fprintf.(the new values should start at the top of the file - rewind() function did not work)</p><p>2. How can I print a USTR format to a text file?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ma3stro)</author>
		<pubDate>Fri, 18 Oct 2013 03:19:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Once you&#39;re done reading the file, close it, and then either delete it or open it in write only mode. That will reset the file contents. Otherwise, you can only overwrite or append, but not truncate.</p><p>And what do you mean rewind didn&#39;t work? Post code, and the text file it is supposed to be working on if necessary.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Fri, 18 Oct 2013 04:04:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>For 1), you need something like ftruncate() to reset the (disk) size of a file that is already open in &quot;w+&quot; mode. If it&#39;s not available on your platform, you can still use the universal method of :<br />- open the file in &quot;r&quot; mode,<br />- read what you need,<br />- close it,<br />- open the same file in &quot;w&quot; mode this time.<br />- write what you need<br />- close
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Fri, 18 Oct 2013 04:09:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>For 2, there are allegro functions which convert ALLEGR0_USTR to c string.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aikei_c)</author>
		<pubDate>Fri, 18 Oct 2013 10:40:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I tried what you told me but it doesn&#39;t seem to work on this:</p><p>.<br />.<br />.</p><p>if(code == Bus[5].code)<br />  file1 = fopen(&quot;list6.txt&quot;, &quot;a+&quot;);</p><p>for(int j=0; j&lt;32; j++)<br />  fscanf(file1, &quot;%d	%c\n&quot;, &amp;Seat[j].no, &amp;Seat[j].type);<br />				<br />fclose(file1);</p><p>.<br />.<br />.</p><p>The reason I can&#39;t open file in &quot;r&quot; mode is beacuse I&#39;m using the struct values and they&#39;re just two members of the struct. And if I use &quot;a+&quot; mode when I reopen the file it starts writing at the end.  </p><p>It&#39;s perfectly reading, when I use the code above. I don&#39;t now what to do at the writing part. Whenever I use the &quot;rewind(file1)&quot;, program crashes.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ma3stro)</author>
		<pubDate>Fri, 18 Oct 2013 14:00:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>The reason I can&#39;t open file in &quot;r&quot; mode is beacuse I&#39;m using the struct values and they&#39;re just two members of the struct.</p></div></div><p>
I have no idea what you&#39;re trying to say here.</p><p>If you intend to read stuff from a file (as you do with fscanf), open the file with &quot;r&quot;. If you intend to write stuff to the file (with fprintf, say), open it with &quot;w&quot; (or &quot;a&quot; if you want to append to the end of the file). If you want to be able to do both, add &quot;+&quot; to the string (note that there&#39;s a difference between &quot;r+&quot; and &quot;w+&quot;, at least according to the man page; I&#39;ve never used either).</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Whenever I use the &quot;rewind(file1)&quot;, program crashes.</p></div></div><p>
Just to make sure: you didn&#39;t close the file first (with fclose()), did you?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Fri, 18 Oct 2013 15:59:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I should be reading &quot;Bus[].no&quot; and &quot;Bus[].type&quot; from the file but there are other members in struct Bus. At first I tried to use &quot;fwrite()&quot; but it writes down the whole struct members and I don&#39;t need that happen. </p><p>If I open the file in &quot;r&quot; mode it will always read the first line. I&#39;m opening it in &quot;a+&quot; so I can read all the &quot;Bus[1].type, Bus[2].type ...&quot; in a for loop.</p><p>Program reads the file correctly, there&#39;s no problem at this point. But when it comes to writing, it appends new values to the end of the file.</p><p>And I used the rewind() function before closing the file but I got a fatal error.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ma3stro)</author>
		<pubDate>Fri, 18 Oct 2013 16:30:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Double check the loop of your program. And post some code, so we can help!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Gabriel Campos)</author>
		<pubDate>Fri, 18 Oct 2013 16:52:15 +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/613391/991453#target">ma3stro</a> said:</div><div class="quote"><p>
If I open the file in &quot;r&quot; mode it will always read the first line.
</p></div></div><p>
What? You can seek with fseek and fsetpos. But you have to know where in the file you should seek to.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I&#39;m opening it in &quot;a+&quot; so I can read all the &quot;Bus[1].type, Bus[2].type ...&quot; in a for loop.
</p></div></div><p>
Open it in &quot;r+&quot;. That is the read/write mode. If you want to append to the end, use <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_354.html" target="_blank">fseek</a><span class="k2">(</span>myfile , <span class="n">0</span> , SEEK_END<span class="k2">)</span><span class="k2">;</span></span> to move to the end of the file.</p><p>rewind shouldn&#39;t crash unless you&#39;ve passed it an invalid FILE*.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Fri, 18 Oct 2013 19:51:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The file appears to be text (&quot;list6.txt&quot;, fscanf() with %d format), so there is no guarantee that the written strings are as long as the previous ones.<br />I expect trouble if the file is not explicitly truncated. (specifically : if you rewrite only 200 bytes of a 220byte file, the last 20 ones will still be there)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Fri, 18 Oct 2013 21:39:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you all for your help. The file reading &amp; writing parts are working just fine. (I used fseek() function)</p><p>I haven&#39;t found a solution for the 2nd question yet. I had a look at the manual but couldn&#39;t figure out which one to use. There is &quot;al_ustr_append_cstr()&quot; function but not the opposite one. </p><p>In my project I&#39;m using:</p><p>.<br />.<br />ALLEGRO_USTR *date= al_ustr_new(&quot;&quot;);<br />char *Date;<br />.<br />.</p><p>I&#39;m getting date from user then print it on the screen. Now I need to assign &quot;date&quot; to &quot;Date&quot; in order to write it on the file. I tried &quot;al_ustr_insert_cstr(date, 0, Date);&quot; but got an error. What am I doing wrong?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ma3stro)</author>
		<pubDate>Sat, 19 Oct 2013 04:35:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>See <span class="source-code"><a href="http://www.allegro.cc/manual/al_ustr_new_from_buffer"><span class="a">al_ustr_new_from_buffer</span></a></span> and <span class="source-code"><a href="http://www.allegro.cc/manual/al_cstr"><span class="a">al_cstr</span></a></span>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 19 Oct 2013 09:25:23 +0000</pubDate>
	</item>
	<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><a href="http://www.allegro.cc/manual/ALLEGRO_USTR"><span class="a">ALLEGRO_USTR</span></a> <span class="k3">*</span>date<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">""</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  2</span><a href="http://www.allegro.cc/manual/ALLEGRO_USTR"><span class="a">ALLEGRO_USTR</span></a> <span class="k3">*</span>name<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">""</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  3</span><a href="http://www.allegro.cc/manual/ALLEGRO_USTR"><span class="a">ALLEGRO_USTR</span></a> <span class="k3">*</span>tel <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">""</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  4</span>
<span class="number">  5</span><span class="k1">char</span> <span class="k3">*</span>departure<span class="k2">;</span>
<span class="number">  6</span><span class="k1">char</span> <span class="k3">*</span>arrival<span class="k2">;</span>
<span class="number">  7</span><span class="k1">char</span> <span class="k3">*</span>cost<span class="k2">;</span>
<span class="number">  8</span><span class="k1">char</span> <span class="k3">*</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a><span class="k2">;</span>
<span class="number">  9</span><span class="k1">char</span> <span class="k3">*</span>bus_code<span class="k2">;</span>
<span class="number"> 10</span><span class="k1">char</span> <span class="k3">*</span>gender<span class="k2">;</span>
<span class="number"> 11</span><span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>Date<span class="k2">;</span>
<span class="number"> 12</span><span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>Tel<span class="k2">;</span>
<span class="number"> 13</span><span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>Name<span class="k2">;</span>
<span class="number"> 14</span>.
<span class="number"> 15</span>.
<span class="number"> 16</span>.
<span class="number"> 17</span>Date<span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_cstr"><span class="a">al_cstr</span></a><span class="k2">(</span>date<span class="k2">)</span>
<span class="number"> 18</span>Name<span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_cstr"><span class="a">al_cstr</span></a><span class="k2">(</span>name<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>Tel <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_cstr"><span class="a">al_cstr</span></a><span class="k2">(</span>tel<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 20</span>.
<span class="number"> 21</span>.
<span class="number"> 22</span>.
<span class="number"> 23</span><span class="k1">if</span><span class="k2">(</span>mouse<span class="k2">[</span>B1<span class="k2">]</span><span class="k2">)</span>
<span class="number"> 24</span><span class="k2">{</span>
<span class="number"> 25</span>   <span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> i<span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> <span class="n">32</span><span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number"> 26</span>   <span class="k1">if</span><span class="k2">(</span>state.x  <span class="k3">&gt;</span><span class="k3">=</span> Seat<span class="k2">[</span>i<span class="k2">]</span>.x <span class="k3">&amp;</span><span class="k3">&amp;</span> <span class="k2">(</span>state.x  <span class="k3">&lt;</span><span class="k3">=</span> Seat<span class="k2">[</span>i<span class="k2">]</span>.x <span class="k3">+</span> <span class="n">30</span><span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> state.y  <span class="k3">&gt;</span><span class="k3">=</span> Seat<span class="k2">[</span>i<span class="k2">]</span>.y <span class="k3">&amp;</span><span class="k3">&amp;</span> <span class="k2">(</span>state.y  <span class="k3">&lt;</span><span class="k3">=</span> Seat<span class="k2">[</span>i<span class="k2">]</span>.y <span class="k3">+</span> <span class="n">30</span><span class="k2">)</span><span class="k2">)</span>
<span class="number"> 27</span>  <span class="k2">{</span>
<span class="number"> 28</span>    <span class="k1">if</span><span class="k2">(</span>Seat<span class="k2">[</span>i<span class="k2">]</span>.type <span class="k3">=</span><span class="k3">=</span> <span class="s">'E'</span><span class="k2">)</span>
<span class="number"> 29</span>          <a href="http://www.allegro.cc/manual/al_draw_filled_rectangle"><span class="a">al_draw_filled_rectangle</span></a><span class="k2">(</span>Seat<span class="k2">[</span>i<span class="k2">]</span>.x, Seat<span class="k2">[</span>i<span class="k2">]</span>.y, <span class="k2">(</span>Seat<span class="k2">[</span>i<span class="k2">]</span>.x <span class="k3">+</span> <span class="n">30</span><span class="k2">)</span><span class="k2">(</span>Seat<span class="k2">[</span>i<span class="k2">]</span>.y <span class="k3">+</span> <span class="n">30</span><span class="k2">)</span>, <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">200</span>,<span class="n">200</span>,<span class="n">200</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 30</span>            
<span class="number"> 31</span>    file2 <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_337.html" target="_blank">fopen</a><span class="k2">(</span><span class="s">"passengers.txt"</span>, <span class="s">"a+"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 32</span>
<span class="number"> 33</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_345.html" target="_blank">fprintf</a><span class="k2">(</span>file2, <span class="s">"%s  %s  %s  %s  %s  %s  %s  %s  %d\n"</span>,Name, Tel, gender, Date, <a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a>, departure, arrival, bus_code, i<span class="k3">+</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span> 
<span class="number"> 34</span>                
<span class="number"> 35</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_308.html" target="_blank">fclose</a><span class="k2">(</span>file2<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 36</span>
<span class="number"> 37</span>    <span class="k1">if</span><span class="k2">(</span>gender <span class="k3">=</span><span class="k3">=</span> <span class="s">"Male"</span><span class="k2">)</span>
<span class="number"> 38</span>      Seat<span class="k2">[</span>i<span class="k2">]</span>.type <span class="k3">=</span> <span class="s">'M'</span><span class="k2">;</span>
<span class="number"> 39</span>    <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span>gender <span class="k3">=</span><span class="k3">=</span> <span class="s">"Female"</span><span class="k2">)</span>
<span class="number"> 40</span>      Seat<span class="k2">[</span>i<span class="k2">]</span>.type <span class="k3">=</span> <span class="s">'W'</span><span class="k2">;</span>
<span class="number"> 41</span>            
<span class="number"> 42</span>  <span class="k2">}</span>
<span class="number"> 43</span><span class="k2">}</span>
</div></div><p>


Program crashes when it comes to &quot;fprintf()&quot; line. Is there any incompatiblity between CString, const char* and &#39;%s&#39; ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ma3stro)</author>
		<pubDate>Sat, 19 Oct 2013 14:32:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span><span class="k2">(</span>gender <span class="k3">=</span><span class="k3">=</span> <span class="s">"Male"</span><span class="k2">)</span>
      Seat<span class="k2">[</span>i<span class="k2">]</span>.type <span class="k3">=</span> <span class="s">'M'</span><span class="k2">;</span>
    <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span>gender <span class="k3">=</span><span class="k3">=</span> <span class="s">"Female"</span><span class="k2">)</span>
      Seat<span class="k2">[</span>i<span class="k2">]</span>.type <span class="k3">=</span> <span class="s">'W'</span><span class="k2">;</span>
</pre></div></div><p>

This won&#39;t work, you&#39;re comparing the pointers, not the values they point to.<br />Use <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_754.html" target="_blank">strcmp</a></span> or <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_768.html" target="_blank">strncmp</a></span> to compare two C strings.</p><div class="source-code snippet"><div class="inner"><pre> file2 <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_337.html" target="_blank">fopen</a><span class="k2">(</span><span class="s">"passengers.txt"</span>, <span class="s">"a+"</span><span class="k2">)</span><span class="k2">;</span>

    <a href="http://www.delorie.com/djgpp/doc/libc/libc_345.html" target="_blank">fprintf</a><span class="k2">(</span>file2, <span class="s">"%s  %s  %s  %s  %s  %s  %s  %s  %d\n"</span>,Name, Tel, gender, Date, <a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a>, departure, arrival, bus_code, i<span class="k3">+</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span> 
                
    <a href="http://www.delorie.com/djgpp/doc/libc/libc_308.html" target="_blank">fclose</a><span class="k2">(</span>file2<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Open the file once, write all the data you need, then close the file.<br />Don&#39;t repeatedly open and close the file every iteration.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/613391/991501#target">ma3stro</a> said:</div><div class="quote"><p> Program crashes when it comes to &quot;fprintf()&quot; line. Is there any incompatiblity between CString, const char* and &#39;%s&#39; ?</p></div></div><p>Are you sure none of your strings NULL? Or maybe you don&#39;t have write access to the passengers.txt file.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (l j)</author>
		<pubDate>Sat, 19 Oct 2013 16:16:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://">taron</a> said:</div><div class="quote"><p>

     if(gender == &quot;Male&quot;)<br />       Seat[i].type = &#39;M&#39;;<br />     else if(gender == &quot;Female&quot;)<br />       Seat[i].type = &#39;W&#39;;</p><p>This won&#39;t work, you&#39;re comparing the pointers, not the values they point to.<br />Use strcmp or strncmp to compare two C strings.</p></div></div><p>

I use ChooseGender() function before the code above. It process &quot;char *gender&quot; value whether user choose male or female. (e.g. If user clicks male button &quot;gender&quot; will be &quot;Male&quot;). Does that cause a problem?</p><div class="quote_container"><div class="title"><a href="http://">taron</a> said:</div><div class="quote"><p>
Are you sure none of your strings NULL? Or maybe you don&#39;t have write access to the passengers.txt file.
</p></div></div><p>

I moved &quot;fopen()&quot; function somwhere else it didn&#39;t cause an error. </p><div class="quote_container"><div class="title"><a href="http://">taron</a> said:</div><div class="quote"><p>
Open the file once, write all the data you need, then close the file.<br />Don&#39;t repeatedly open and close the file every iteration.
</p></div></div><p>

Thanks, that&#39;s more efficient but still have problem at &quot;fprintf()&quot; line.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ma3stro)</author>
		<pubDate>Sat, 19 Oct 2013 16:38:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Did you change the ALLEGRO_USTR* after converting it to const char*? If you did, the pointer to const char* became invalid after that.<br />How does it crash? What does the compiler say?<br />EDIT: you don&#39;t even need to make this strange thing with declaring two different variables for one string.<br />If you want to pass ustr to fprintf, you just do this:</p><div class="source-code snippet"><div class="inner"><pre>file <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_337.html" target="_blank">fopen</a><span class="k2">(</span><span class="s">"file.txt"</span>, <span class="s">"w"</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/ALLEGRO_USTR"><span class="a">ALLEGRO_USTR</span></a><span class="k3">*</span> uString <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">"Hi!"</span><span class="k2">)</span><span class="k2">;</span>
frintf<span class="k2">(</span>file,<span class="s">"%s"</span>,<a href="http://www.allegro.cc/manual/al_cstr"><span class="a">al_cstr</span></a><span class="k2">(</span>uString<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aikei_c)</author>
		<pubDate>Sat, 19 Oct 2013 17:07:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://">Aikei_c</a> said:</div><div class="quote"><p>
Did you change the ALLEGRO_USTR* after converting it to const char*? If you did, the pointer to const char* became invalid after that.<br />How does it crash? What does the compiler say?
</p></div></div><p>

No, I did not change it. And the error is:</p><p>Unhandled exception at 0x55b913af (msvcr100d.dll) in Ticket_Automation.exe: 0xC0000005: Access violation reading location 0x000001b3.</p><div class="quote_container"><div class="title"><a href="http://">Aikei_c</a> said:</div><div class="quote"><p>
EDIT: you don&#39;t even need to make this strange thing with declaring two different variables for one string.<br />If you want to pass ustr to fprintf, you just do this:</p><p>file = fopen(&quot;file.txt&quot;, &quot;a&quot;);<br />ALLEGRO_USTR* uString = al_ustr_new(&quot;Hi!&quot;);<br />frintf(file,&quot;%s&quot;,al_cstr(uString));
</p></div></div><p>

Ok. I will try that.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ma3stro)</author>
		<pubDate>Sat, 19 Oct 2013 17:32:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Another way you could check what is crashing is to just initially fprintf a string literal such as &quot;Hello World&quot; and make sure that works fine.  Then add your other variables until you work out which one is causing the crash.  That might give you a hint as to where the problem lies.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Sat, 19 Oct 2013 17:39:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://">Aikei_c</a> said:</div><div class="quote"><p>
file = fopen(&quot;file.txt&quot;, &quot;w&quot;);<br />ALLEGRO_USTR* uString = al_ustr_new(&quot;Hi!&quot;);<br />frintf(file,&quot;%s&quot;,al_cstr(uString));
</p></div></div><p>

That didn&#39;t work either.</p><p>I changed this,</p><p>fprintf(file2, &quot;%s  %s  %s  %s  %s  %s  %s  %s  %d\n&quot;,Name, Tel, gender, Date, time, departure, arrival, bus_code, i+1); </p><p>to this:</p><p>fprintf(file2, &quot;%d\n&quot; i+1); </p><p>and there weren&#39;t any problems at all. So it&#39;s the strings that cause the error.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ma3stro)</author>
		<pubDate>Sat, 19 Oct 2013 17:50:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Does this work:</p><p><span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_345.html" target="_blank">fprintf</a><span class="k2">(</span>file2, <span class="s">"%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_ustr_new"><span class="a">al_ustr_new</span></a><span class="k2">(</span><span class="s">"Hello World!"</span><span class="k2">)</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Sat, 19 Oct 2013 17:59:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://">LennyLen</a> said:</div><div class="quote"><p>
Does this work:</p><p>fprintf(file2, &quot;%s\n&quot;, al_cstr(al_ustr_new(&quot;Hello World!&quot;)));
</p></div></div><p>

Yes, it does.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ma3stro)</author>
		<pubDate>Sat, 19 Oct 2013 18:02:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Then the problem is with your ALLEGRO_USTR values, somewhere in the code you haven&#39;t shown us.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Sat, 19 Oct 2013 18:21:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This is how I use one of the ALLEGRO_USTR variables:
</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>date<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">""</span><span class="k2">)</span><span class="k2">;</span>  
<span class="number">  2</span><span class="k1">int</span> pos <span class="k3">=</span> <span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><a href="http://www.allegro.cc/manual/al_ustr_size"><span class="a">al_ustr_size</span></a><span class="k2">(</span>date<span class="k2">)</span><span class="k2">;</span>
<span class="number">  3</span>.
<span class="number">  4</span>.
<span class="number">  5</span><span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>done<span class="k2">)</span> <span class="c">// If user hits enter done will be true</span>
<span class="number">  6</span><span class="k2">{</span>  <span class="k1">if</span><span class="k2">(</span>STATE <span class="k3">=</span><span class="k3">=</span> DATE<span class="k2">)</span>
<span class="number">  7</span>        <span class="k1">if</span><span class="k2">(</span>events.keyboard.unichar <span class="k3">&gt;</span><span class="k3">=</span> <span class="n">32</span><span class="k2">)</span>
<span class="number">  8</span>              <span class="k2">{</span>
<span class="number">  9</span>                pos <span class="k3">+</span><span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_ustr_append_chr"><span class="a">al_ustr_append_chr</span></a><span class="k2">(</span>date, events.keyboard.unichar<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span>              <span class="k2">}</span>
<span class="number"> 11</span>              <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span>events.keyboard.keycode <span class="k3">=</span><span class="k3">=</span> ALLEGRO_KEY_BACKSPACE<span class="k2">)</span>
<span class="number"> 12</span>              <span class="k2">{</span>
<span class="number"> 13</span>                <span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_ustr_prev"><span class="a">al_ustr_prev</span></a><span class="k2">(</span>date, <span class="k3">&amp;</span>pos<span class="k2">)</span><span class="k2">)</span>
<span class="number"> 14</span>                  <a href="http://www.allegro.cc/manual/al_ustr_truncate"><span class="a">al_ustr_truncate</span></a><span class="k2">(</span>date, pos<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span>              <span class="k2">}</span>
<span class="number"> 16</span>.
<span class="number"> 17</span>.
<span class="number"> 18</span>.
<span class="number"> 19</span><span class="k1">if</span><span class="k2">(</span>STATE <span class="k3">=</span><span class="k3">=</span> DATE<span class="k2">)</span>
<span class="number"> 20</span>    <span class="k2">{</span>
<span class="number"> 21</span>      <a href="http://www.allegro.cc/manual/al_draw_ustr"><span class="a">al_draw_ustr</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>, <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">0</span>,<span class="n">0</span>,<span class="n">0</span><span class="k2">)</span>, <span class="n">260</span>, <span class="n">21</span>, <span class="n">0</span>, date<span class="k2">)</span><span class="k2">;</span>      
<span class="number"> 22</span>    <span class="k2">}</span>
<span class="number"> 23</span>.
<span class="number"> 24</span>.
<span class="number"> 25</span>.
<span class="number"> 26</span><span class="k1">if</span><span class="k2">(</span>mouse<span class="k2">[</span>B1<span class="k2">]</span><span class="k2">)</span>
<span class="number"> 27</span> <span class="k2">{</span>
<span class="number"> 28</span>   file2 <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_337.html" target="_blank">fopen</a><span class="k2">(</span><span class="s">"passengers.txt"</span>, <span class="s">"a+"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 29</span>
<span class="number"> 30</span>   <span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> i<span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> <span class="n">32</span><span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number"> 31</span>   <span class="k1">if</span><span class="k2">(</span>state.x  <span class="k3">&gt;</span><span class="k3">=</span> Seat<span class="k2">[</span>i<span class="k2">]</span>.x <span class="k3">&amp;</span><span class="k3">&amp;</span> <span class="k2">(</span>state.x  <span class="k3">&lt;</span><span class="k3">=</span> Seat<span class="k2">[</span>i<span class="k2">]</span>.x <span class="k3">+</span> <span class="n">30</span><span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> state.y  <span class="k3">&gt;</span><span class="k3">=</span> Seat<span class="k2">[</span>i<span class="k2">]</span>.y <span class="k3">&amp;</span><span class="k3">&amp;</span> <span class="k2">(</span>state.y  <span class="k3">&lt;</span><span class="k3">=</span> Seat<span class="k2">[</span>i<span class="k2">]</span>.y <span class="k3">+</span> <span class="n">30</span><span class="k2">)</span><span class="k2">)</span>
<span class="number"> 32</span>  <span class="k2">{</span>
<span class="number"> 33</span>     <span class="k1">if</span><span class="k2">(</span>Seat<span class="k2">[</span>i<span class="k2">]</span>.type <span class="k3">=</span><span class="k3">=</span> <span class="s">'E'</span><span class="k2">)</span>
<span class="number"> 34</span>          <a href="http://www.allegro.cc/manual/al_draw_filled_rectangle"><span class="a">al_draw_filled_rectangle</span></a><span class="k2">(</span>Seat<span class="k2">[</span>i<span class="k2">]</span>.x, Seat<span class="k2">[</span>i<span class="k2">]</span>.y, <span class="k2">(</span>Seat<span class="k2">[</span>i<span class="k2">]</span>.x <span class="k3">+</span> <span class="n">30</span><span class="k2">)</span><span class="k2">(</span>Seat<span class="k2">[</span>i<span class="k2">]</span>.y <span class="k3">+</span> <span class="n">30</span><span class="k2">)</span>, <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">200</span>,<span class="n">200</span>,<span class="n">200</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 35</span>            
<span class="number"> 36</span> 
<span class="number"> 37</span>     <a href="http://www.delorie.com/djgpp/doc/libc/libc_345.html" target="_blank">fprintf</a><span class="k2">(</span>file2, <span class="s">"%s  %s  %s  %s  %s  %s  %s  %s  %d\n"</span>,<a href="http://www.allegro.cc/manual/al_cstr"><span class="a">al_cstr</span></a><span class="k2">(</span>name<span class="k2">)</span>,<a href="http://www.allegro.cc/manual/al_cstr"><span class="a">al_cstr</span></a><span class="k2">(</span>tel<span class="k2">)</span>, gender, <a href="http://www.allegro.cc/manual/al_cstr"><span class="a">al_cstr</span></a><span class="k2">(</span>date<span class="k2">)</span>, <a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a>, departure, arrival, bus_code, i<span class="k3">+</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span> 
<span class="number"> 38</span>                 
<span class="number"> 39</span>
<span class="number"> 40</span>    <span class="k1">if</span><span class="k2">(</span>gender <span class="k3">=</span><span class="k3">=</span> <span class="s">"Male"</span><span class="k2">)</span>
<span class="number"> 41</span>       Seat<span class="k2">[</span>i<span class="k2">]</span>.type <span class="k3">=</span> <span class="s">'M'</span><span class="k2">;</span>
<span class="number"> 42</span>    <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span>gender <span class="k3">=</span><span class="k3">=</span> <span class="s">"Female"</span><span class="k2">)</span>
<span class="number"> 43</span>       Seat<span class="k2">[</span>i<span class="k2">]</span>.type <span class="k3">=</span> <span class="s">'W'</span><span class="k2">;</span>
<span class="number"> 44</span>             
<span class="number"> 45</span>  <span class="k2">}</span>
<span class="number"> 46</span>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_308.html" target="_blank">fclose</a><span class="k2">(</span>file2<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 47</span> <span class="k2">}</span>
<span class="number"> 48</span>.
<span class="number"> 49</span>.
<span class="number"> 50</span>.
<span class="number"> 51</span><a href="http://www.allegro.cc/manual/al_ustr_free"><span class="a">al_ustr_free</span></a><span class="k2">(</span>date<span class="k2">)</span><span class="k2">;</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ma3stro)</author>
		<pubDate>Sat, 19 Oct 2013 19:12:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Use just one argument: al_cstr(name). Does it work? If not, try to understand, why. If it doesn&#39;t add another argument. Does it work?..<br />Keep on until you identify your problem.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aikei_c)</author>
		<pubDate>Sun, 20 Oct 2013 01:59:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I tried all the parameters one by one and found that &quot;gender&quot; value is the problem. The others are working fine.</p><div class="quote_container"><div class="title"><a href="http://">taron</a> said:</div><div class="quote"><p>
if(gender == &quot;Male&quot;)<br />      Seat[i].type = &#39;M&#39;;<br />    else if(gender == &quot;Female&quot;)<br />      Seat[i].type = &#39;W&#39;;<br />This won&#39;t work, you&#39;re comparing the pointers, not the values they point to.<br />Use strcmp or strncmp to compare two C strings.
</p></div></div><p>

I think this is where things have gone wrong. </p><p>For strcmp(), do I have to create another string variable ( e.g. char *str = &quot;Male&quot; ) and compare those two(gender and str)?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ma3stro)</author>
		<pubDate>Sun, 20 Oct 2013 03:52:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No, it can&#39;t be that, since 1) it happens after printf, 2) it doesn&#39;t change gender in any way.<br />If <span class="source-code">gender</span> causes the problem then the <span class="source-code">gender</span> pointer doesn&#39;t point to valid text data. Where do you assign value to <span class="source-code">gender</span>? Problem is there somewhere.<br />To compare c strings you do this:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_754.html" target="_blank">strcmp</a><span class="k2">(</span>gender,<span class="s">"Male"</span><span class="k2">)</span> <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span> <span class="c">//if gender is "Male"</span>
   <span class="c">//do something</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aikei_c)</author>
		<pubDate>Sun, 20 Oct 2013 04:02:52 +0000</pubDate>
	</item>
	<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="k1">void</span> ChooseGender<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_MOUSE_STATE"><span class="a">ALLEGRO_MOUSE_STATE</span></a> state<span class="k2">)</span>
<span class="number">  2</span><span class="k2">{</span>
<span class="number">  3</span>  <span class="k1">if</span><span class="k2">(</span>mouse<span class="k2">[</span>B1<span class="k2">]</span><span class="k2">)</span>
<span class="number">  4</span>    <span class="k1">if</span><span class="k2">(</span>state.x <span class="k3">&gt;</span><span class="k3">=</span> <span class="n">100</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> state.x <span class="k3">&lt;</span><span class="k3">=</span> <span class="n">113</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> state.y <span class="k3">&gt;</span><span class="k3">=</span> <span class="n">112</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> state.y <span class="k3">&lt;</span><span class="k3">=</span> <span class="n">125</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_draw_filled_rectangle"><span class="a">al_draw_filled_rectangle</span></a><span class="k2">(</span><span class="n">100</span>, <span class="n">112</span>, <span class="n">113</span>, <span class="n">125</span>, <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">0</span>,<span class="n">0</span>,<span class="n">0</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span> 
<span class="number">  7</span>      gender <span class="k3">=</span> <span class="s">"Male"</span><span class="k2">;</span>
<span class="number">  8</span>    <span class="k2">}</span>
<span class="number">  9</span>    <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span>state.x <span class="k3">&gt;</span><span class="k3">=</span> <span class="n">200</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> state.x <span class="k3">&lt;</span><span class="k3">=</span> <span class="n">213</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> state.y <span class="k3">&gt;</span><span class="k3">=</span> <span class="n">112</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> state.y <span class="k3">&lt;</span><span class="k3">=</span> <span class="n">125</span> <span class="k2">)</span>
<span class="number"> 10</span>    <span class="k2">{</span>  
<span class="number"> 11</span>      <a href="http://www.allegro.cc/manual/al_draw_filled_rectangle"><span class="a">al_draw_filled_rectangle</span></a><span class="k2">(</span><span class="n">200</span>, <span class="n">112</span>, <span class="n">213</span>, <span class="n">125</span>, <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">0</span>,<span class="n">0</span>,<span class="n">0</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span> 
<span class="number"> 12</span>      gender <span class="k3">=</span> <span class="s">"Female"</span><span class="k2">;</span>
<span class="number"> 13</span>    <span class="k2">}</span>
<span class="number"> 14</span>
<span class="number"> 15</span><span class="k2">}</span>
</div></div><p>

I am using this function to get user gender.<br /> <br />I tried something else: </p><p>I changed &quot;char *gender&quot; to &quot;char gender&quot;, &quot;Male&quot; to &#39;m&#39; , &quot;Female&quot; to &#39;f&#39; and %d to %c. It worked but &#39;â&#39; was written in the file not &#39;f&#39; or &#39;m&#39;. </p><p>EDIT: strcmp() didn&#39;t work either.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ma3stro)</author>
		<pubDate>Sun, 20 Oct 2013 04:13:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You&#39;re not listening. You can&#39;t compare const char* by using the equivalence operator. That compares the addresses they store, not the data at those addresses. That&#39;s why you have to use <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_754.html" target="_blank">strcmp</a></span>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sun, 20 Oct 2013 04:34:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://">Edgar Reynaldo</a> said:</div><div class="quote"><p>
You&#39;re not listening. You can&#39;t compare const char* by using the equivalence operator. That compares the addresses they store, not the data at those addresses. That&#39;s why you have to use strcmp.
</p></div></div><p>

Why wouldn&#39;t I listen while seeking for help? I wrote in my last message,  I used strcmp() but it didn&#39;t work. </p><p>I used this:
</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><span class="k1">int</span> value<span class="k2">;</span>
<span class="number">  2</span>.
<span class="number">  3</span>.
<span class="number">  4</span>.
<span class="number">  5</span><span class="k1">void</span> ChooseGender<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_MOUSE_STATE"><span class="a">ALLEGRO_MOUSE_STATE</span></a> state<span class="k2">)</span>
<span class="number">  6</span><span class="k2">{</span>
<span class="number">  7</span>  <span class="k1">if</span><span class="k2">(</span>mouse<span class="k2">[</span>B1<span class="k2">]</span><span class="k2">)</span>
<span class="number">  8</span>    <span class="k1">if</span><span class="k2">(</span>state.x <span class="k3">&gt;</span><span class="k3">=</span> <span class="n">100</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> state.x <span class="k3">&lt;</span><span class="k3">=</span> <span class="n">113</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> state.y <span class="k3">&gt;</span><span class="k3">=</span> <span class="n">112</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> state.y <span class="k3">&lt;</span><span class="k3">=</span> <span class="n">125</span> <span class="k2">)</span>
<span class="number">  9</span>    <span class="k2">{</span>
<span class="number"> 10</span>      <a href="http://www.allegro.cc/manual/al_draw_filled_rectangle"><span class="a">al_draw_filled_rectangle</span></a><span class="k2">(</span><span class="n">100</span>, <span class="n">112</span>, <span class="n">113</span>, <span class="n">125</span>, <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">0</span>,<span class="n">0</span>,<span class="n">0</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span> 
<span class="number"> 11</span>      value <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> <span class="c">// Male</span>
<span class="number"> 12</span>    <span class="k2">}</span>
<span class="number"> 13</span>    <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span>state.x <span class="k3">&gt;</span><span class="k3">=</span> <span class="n">200</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> state.x <span class="k3">&lt;</span><span class="k3">=</span> <span class="n">213</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> state.y <span class="k3">&gt;</span><span class="k3">=</span> <span class="n">112</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> state.y <span class="k3">&lt;</span><span class="k3">=</span> <span class="n">125</span> <span class="k2">)</span>
<span class="number"> 14</span>    <span class="k2">{</span>  
<span class="number"> 15</span>      <a href="http://www.allegro.cc/manual/al_draw_filled_rectangle"><span class="a">al_draw_filled_rectangle</span></a><span class="k2">(</span><span class="n">200</span>, <span class="n">112</span>, <span class="n">213</span>, <span class="n">125</span>, <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">0</span>,<span class="n">0</span>,<span class="n">0</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span> 
<span class="number"> 16</span>      value <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span> <span class="c">//Female</span>
<span class="number"> 17</span>    <span class="k2">}</span>
<span class="number"> 18</span>
<span class="number"> 19</span><span class="k2">}</span>
<span class="number"> 20</span>.
<span class="number"> 21</span>.
<span class="number"> 22</span>.
<span class="number"> 23</span><span class="k1">if</span> <span class="k2">(</span>value <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span>
<span class="number"> 24</span>        cinsiyet <span class="k3">=</span> <span class="s">"Male"</span><span class="k2">;</span>
<span class="number"> 25</span>      <span class="k1">else</span> 
<span class="number"> 26</span>        cinsiyet <span class="k3">=</span> <span class="s">"Female"</span><span class="k2">;</span>
</div></div><p>

and it worked! <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />  Not the efficient way though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ma3stro)</author>
		<pubDate>Sun, 20 Oct 2013 04:52:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s actually more efficient than comparing strings.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 20 Oct 2013 04:58:06 +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/613391/991560#target">ma3stro</a> said:</div><div class="quote"><p>
Why wouldn&#39;t I listen while seeking for help? I wrote in my last message,  I used strcmp() but it didn&#39;t work. 
</p></div></div><p>
Sorry, I didn&#39;t see your edit. What do you mean, strcmp didn&#39;t work? How were you using it? It returns a negative number, 0, or a positive number based on the ascii collating sequence. Negative if the first string comes before, 0 if they are equivalent, and positive if the first string comes after the second.</p><p>I think your problem is that you are thinking of const char* as if they are strings. They really aren&#39;t. They are pointers to an array of char. I used to think that way when I first started using C++. You would think you could just compare them with the equivalence operator, and you can, but that only compares the addresses they store. And curiously enough, <span class="source-code"><span class="k1">if</span> <span class="k2">(</span><span class="s">"string"</span> <span class="k3">=</span><span class="k3">=</span> <span class="s">"string"</span><span class="k2">)</span><span class="k2">;</span></span> is valid code, but it is comparing two static addresses. Literal strings are usually allocated statically by the compiler, meaning there is usually only one instance of &quot;string&quot; even if you reference it more than once.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sun, 20 Oct 2013 05:20:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, I thought it worked but it was not. Program always saves passengers as &quot;Female&quot; because the if statement doesn&#39;t provide &#39;0&#39; then it goes for else. If I change &#39;else&#39; to &#39;else if&#39; error will be back.</p><p>I think the problem is in &#39;ChooseGender()&#39;. Mouse[B1] becomes true just before program reaches to function line and &#39;mouse.state&#39; cannot catch the coordinates and it always returns false.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ma3stro)</author>
		<pubDate>Sun, 20 Oct 2013 05:45:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you don&#39;t mind, I&#39;d like to see your latest code.</p><p>Here&#39;s how I would check for gender equivalence.</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">bool</span> male <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span>

male <span class="k3">=</span> <span class="k2">(</span>expression_with_condition_for_being_male<span class="k2">)</span><span class="k2">;</span>

<span class="k1">const</span> <span class="k1">char</span><span class="k3">*</span> gender <span class="k3">=</span> <span class="k2">(</span>male?<span class="s">"Male"</span><span class="k2">:</span><span class="s">"Female"</span><span class="k2">)</span><span class="k2">;</span>
<span class="c">// this is the same as if you said</span>
<span class="c">// if (male) {gender = "Male";} else {gender = "Female";}</span>

<a href="http://www.allegro.cc/manual/al_draw_textf"><span class="a">al_draw_textf</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a> , allegro_color , x , y , <span class="s">"Gender = %s"</span> , gender<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sun, 20 Oct 2013 05:54:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://">Edgar Reynaldo</a> said:</div><div class="quote"><p>
If you don&#39;t mind, I&#39;d like to see your latest code.</p><p>Here&#39;s how I would check for gender equivalence.</p><p>bool male = true;</p><p>male = (expression_with_condition_for_being_male);</p><p>const char* gender = (male?&quot;Male&quot;:&quot;Female&quot;);<br />// this is the same as if you said<br />// if (male) {gender = &quot;Male&quot;;} else {gender = &quot;Female&quot;;}</p><p>al_draw_textf(font , allegro_color , x , y , &quot;Gender = %s&quot; , gender);
</p></div></div><p>

Sorry for not responding. I handed in the project on Tuesday. I used a boolean type variable(male) and deleted the string comparison part(which was no longer necessary).  </p><p>Thank you all for your help, I appreciate it!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ma3stro)</author>
		<pubDate>Wed, 23 Oct 2013 21:10:52 +0000</pubDate>
	</item>
</rss>
