<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>fopen</title>
		<link>http://www.allegro.cc/forums/view/591415</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 20 May 2007 04:21:42 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have gotten a problem.. I want to save my texture in a text file. This way I can simple write a texture in notepad <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><div class="source-code snippet"><div class="inner"><pre>FILE<span class="k3">*</span> cfg<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">"poly.cfg.txt"</span>,<span class="s">"r"</span><span class="k2">)</span><span class="k2">;</span>
  
  <span class="k1">if</span><span class="k2">(</span>cfg<span class="k3">=</span><span class="k3">=</span>NULL<span class="k2">)</span>
    <span class="k1">return</span> <span class="n">1</span><span class="k2">;</span>
</pre></div></div><p>

And, the function returns 1. I have  no idea why. I have tentheled (tripled you can say :p) check the name. It was originally poly.cfg.. I thought maybe it needs a *.txt file. The file is a text file, created and edited in notepad. I am using VS6.</p><p>The *.exe file and my text file are in the same directory.</p><p>Can anybody please tell me, why  would &quot;fopen(&quot;poly.cfg.txt&quot;,&quot;r&quot;);&quot; return NULL? Thanks..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (type568)</author>
		<pubDate>Wed, 16 May 2007 20:00:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Second argument.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Inphernic)</author>
		<pubDate>Wed, 16 May 2007 20:21:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I second Inphernic , but I will give you the tip he mention: <br />fopen(&quot;myfile.txt&quot;,&quot;r<b>w</b>&quot;);
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Wed, 16 May 2007 20:46:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>... and now he&#39;ll never learn to look things up for himself.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Wed, 16 May 2007 20:55:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No.. This didn&#39;t help. cfg==NULL is true. And, by the way: in the borland 3.1 1992, which help I am using, uses &quot;r&quot;.</p><p>Edit: Can there be any other reason.. ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (type568)</author>
		<pubDate>Wed, 16 May 2007 22:24:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Are you running from the IDE? Visual Studio runs exe&#39;s from a different path, so the text file shouldn&#39;t be in the path with the exe unless you are running it directly (eg double clicking on the exe as opposed to running from the IDE). I think it&#39;s one level up, but different projects can have different settings.</p><p>Test running the exe directly and see if it helps.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Hard Rock)</author>
		<pubDate>Wed, 16 May 2007 22:34:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks Hard Rick, I had a similar issue with a bitmap, so I tested this before asking for help here..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (type568)</author>
		<pubDate>Wed, 16 May 2007 23:42:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Type568, you imo have two problem. The second was solved (path issue), but the first ...</p><p>If you manage to write something in a file you fopen in <b>r</b>eadable only mode, well, have good time.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Thu, 17 May 2007 01:10:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You shouldn&#39;t be using &quot;rw&quot; unless you want to read AND write. &quot;w&quot; is what you likely want.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Thu, 17 May 2007 01:11:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I wanted to read only.. But generally, ANYTHING. I just want something except for NULL from my fopen()..</p><p>Edit: Maybe somebody has some working code with fopen()? Just something working, with it&#39;s source.</p><p>Here&#39;s mine:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">int</span> init_kyb<span class="k2">(</span><span class="k2">)</span>
  <span class="k2">{</span>
  FILE<span class="k3">*</span> cfg<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">"lol.txt"</span>,<span class="s">"r"</span><span class="k2">)</span><span class="k2">;</span>
  
  <span class="k1">if</span><span class="k2">(</span>cfg<span class="k3">=</span><span class="k3">=</span>NULL<span class="k2">)</span>
    <span class="k1">return</span> <span class="n">1</span><span class="k2">;</span>
        <span class="k2">}</span>
</pre></div></div><p>

All the code, is attached...</p><p>Thanks again.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (type568)</author>
		<pubDate>Thu, 17 May 2007 01:46:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I second Inphernic , but I will give you the tip he mention: <br /> fopen(&quot;myfile.txt&quot;,&quot;rw&quot;);
</p></div></div><p>
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
You shouldn&#39;t be using &quot;rw&quot; unless you want to read AND write. &quot;w&quot; is what you likely want.
</p></div></div><p>
Is that a <i>MSVC</i> standard?</p><p>I thought that it was <b>r+</b> .
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Archon)</author>
		<pubDate>Thu, 17 May 2007 06:40:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No, it&#39;s just r.<br />If it doesn&#39;t accept just r, burn your hard disk and install Linux and gcc.</p><p>EDIT:<br />Don&#39;t try installing to your burnt hard disk, that would really ruin your experience of Linux - get another hard disk first. Or don&#39;t burn the other in the first place. Sorry if this is too late now.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (James Stanley)</author>
		<pubDate>Thu, 17 May 2007 12:35:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Check the <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_293.html" target="_blank">errno</a></span> value after <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_337.html" target="_blank">fopen</a></span> to see where is the problem.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (clovekx)</author>
		<pubDate>Thu, 17 May 2007 13:56:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>or perror(&quot;fopen&quot;);
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (James Stanley)</author>
		<pubDate>Thu, 17 May 2007 15:27:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How about creating a file and searching for it? That way you can know your path. And here&#39;s a better way to make sure you will load the file:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">char</span> name<span class="k2">[</span><span class="n">200</span><span class="k2">]</span><span class="k2">;</span>

<a href="http://www.allegro.cc/manual/get_executable_name" target="_blank"><span class="a">get_executable_name</span></a><span class="k2">(</span>name, <span class="k1">sizeof</span><span class="k2">(</span>name<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/replace_filename" target="_blank"><span class="a">replace_filename</span></a><span class="k2">(</span>name, name, <span class="s">"poly.cfg"</span>, <span class="k1">sizeof</span><span class="k2">(</span>name<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
FILE <span class="k3">*</span> cfg <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_337.html" target="_blank">fopen</a><span class="k2">(</span>name,<span class="s">"r"</span><span class="k2">)</span><span class="k2">;</span>

<span class="k1">if</span><span class="k2">(</span>cfg <span class="k3">=</span><span class="k3">=</span> NULL<span class="k2">)</span>
    <span class="k1">return</span> <span class="n">1</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
There&#39;s also a way to change the execution path, but I don&#39;t remember how.</p><p>EDIT: It is called the working directory can be changed using <a href="http://www.delorie.com/djgpp/doc/libc/libc_92.html">chdir</a>. Please note that this is not ANSI C.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ron Ofir)</author>
		<pubDate>Thu, 17 May 2007 16:46:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It probably doesn&#39;t matter given the compiler you&#39;re using, but a long time ago I got in the habit of specifying <i>text</i> or <i>binary</i> input and output, so I&#39;d use &quot;RB&quot; or &quot;RT&quot; as the final argument, assuming you are reading and not writing. If writing open the file with &quot;WB&quot; or &quot;WT&quot;. </p><p>Oddly, with an older version of Borland C++ I&#39;ve had issues with files not properly opening using read/write mode, so I never use that.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Sirocco)</author>
		<pubDate>Thu, 17 May 2007 17:12:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
No, it&#39;s just r.
</p></div></div><p>
I know that that works, but it looks like &quot;rw&quot; is supposed to mean read <b>and</b> write.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Archon)</author>
		<pubDate>Thu, 17 May 2007 17:31:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks a lot, to everybody.. I managed to read the file, and do some nice crap to what I&#39;ve read. Here it is, VS6 workspace, Also <b>the file</b> with an *.exe included :p</p><p>Edit: comments are greatly appreciated :p</p><p>Edit(1): Gnolam, you are totally not right.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (type568)</author>
		<pubDate>Sun, 20 May 2007 04:21:42 +0000</pubDate>
	</item>
</rss>
