<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: C Tutorial &#8211; Binary File I/O</title>
	<atom:link href="http://www.codingunit.com/c-tutorial-binary-file-io/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codingunit.com/c-tutorial-binary-file-io</link>
	<description>CodingUnit is your online resource for learning to program. Tutorials on C, C++, PHP, Python, MySQL, Java, JQuery, Opengl, DirectX and much more!</description>
	<lastBuildDate>Mon, 06 Feb 2012 06:08:16 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: C Tutorial – Binary File I/O &#124; CodingUnit Programming Tutorials &#124; FRANCESCO DI FUSCO</title>
		<link>http://www.codingunit.com/c-tutorial-binary-file-io/comment-page-1#comment-4205</link>
		<dc:creator>C Tutorial – Binary File I/O &#124; CodingUnit Programming Tutorials &#124; FRANCESCO DI FUSCO</dc:creator>
		<pubDate>Wed, 16 Nov 2011 13:37:19 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=218#comment-4205</guid>
		<description>[...] C Tutorial – Binary File I/O &#124; CodingUnit Programming Tutorials. Rate this:  Share this:TwitterFacebookStumbleUponPrintEmailLinkedInLike this:LikeBe the first to [...]</description>
		<content:encoded><![CDATA[<p>[...] C Tutorial – Binary File I/O | CodingUnit Programming Tutorials. Rate this:  Share this:TwitterFacebookStumbleUponPrintEmailLinkedInLike this:LikeBe the first to [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alan</title>
		<link>http://www.codingunit.com/c-tutorial-binary-file-io/comment-page-1#comment-3664</link>
		<dc:creator>Alan</dc:creator>
		<pubDate>Sat, 06 Aug 2011 19:09:44 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=218#comment-3664</guid>
		<description>This was an extremely helpful tutorial. Thank you so much.

I understand that fseek() offsets the pointer by characters. Is there anyway I can offset the pointer by &#039;n&#039; number of lines? I&#039;m trying to write/overwrite a string to a specific line in my text file. I tried

fprintf(myfile+3, &quot;www.codingunit.com&quot;);

but it does not offset my pointer to line 3 in my textfile. Please enlighten me with your wisdom, great one. :)

Thanks again!
Alan</description>
		<content:encoded><![CDATA[<p>This was an extremely helpful tutorial. Thank you so much.</p>
<p>I understand that fseek() offsets the pointer by characters. Is there anyway I can offset the pointer by &#8216;n&#8217; number of lines? I&#8217;m trying to write/overwrite a string to a specific line in my text file. I tried</p>
<p>fprintf(myfile+3, &#8220;www.codingunit.com&#8221;);</p>
<p>but it does not offset my pointer to line 3 in my textfile. Please enlighten me with your wisdom, great one. <img src='http://www.codingunit.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Thanks again!<br />
Alan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: isaiah</title>
		<link>http://www.codingunit.com/c-tutorial-binary-file-io/comment-page-1#comment-3653</link>
		<dc:creator>isaiah</dc:creator>
		<pubDate>Thu, 04 Aug 2011 12:06:54 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=218#comment-3653</guid>
		<description>tnx for some example of the program tnx a lot....more power</description>
		<content:encoded><![CDATA[<p>tnx for some example of the program tnx a lot&#8230;.more power</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.codingunit.com/c-tutorial-binary-file-io/comment-page-1#comment-3401</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Sat, 14 May 2011 12:40:23 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=218#comment-3401</guid>
		<description>@mohammed - It&#039;s very easy to use variables y and z in the first write and read examples. You just have to add some additional lines. The examples now only uses the variable x to keep the examples smaller. To use all three (x,y,z) variables add the following lines to the examples:

Write for loop:
for ( counter=1; counter &lt;= 10; counter++) {
	my_record.x= counter;
	my_record.y= counter;
	my_record.z= counter;
	fwrite(&amp;my_record, sizeof(struct rec), 1, ptr_myfile);
}

The read example:
for ( counter=1; counter &lt;= 10; counter++) {
	fread(&amp;my_record,sizeof(struct rec),1,ptr_myfile);
	printf(&quot;%d\n&quot;,my_record.x);
	printf(&quot;%d\n&quot;,my_record.y);
	printf(&quot;%d\n&quot;,my_record.z);
}

As you can see we only have to fill the other two variables (y and z) as we did with x variable. Then we can read them as we did x in the read example.

Hope this helps!</description>
		<content:encoded><![CDATA[<p>@mohammed &#8211; It&#8217;s very easy to use variables y and z in the first write and read examples. You just have to add some additional lines. The examples now only uses the variable x to keep the examples smaller. To use all three (x,y,z) variables add the following lines to the examples:</p>
<p>Write for loop:<br />
for ( counter=1; counter &lt;= 10; counter++) {<br />
	my_record.x= counter;<br />
	my_record.y= counter;<br />
	my_record.z= counter;<br />
	fwrite(&#038;my_record, sizeof(struct rec), 1, ptr_myfile);<br />
}</p>
<p>The read example:<br />
for ( counter=1; counter <= 10; counter++) {<br />
	fread(&#038;my_record,sizeof(struct rec),1,ptr_myfile);<br />
	printf(&#8220;%d\n&#8221;,my_record.x);<br />
	printf(&#8220;%d\n&#8221;,my_record.y);<br />
	printf(&#8220;%d\n&#8221;,my_record.z);<br />
}</p>
<p>As you can see we only have to fill the other two variables (y and z) as we did with x variable. Then we can read them as we did x in the read example.</p>
<p>Hope this helps!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mohammed</title>
		<link>http://www.codingunit.com/c-tutorial-binary-file-io/comment-page-1#comment-3398</link>
		<dc:creator>mohammed</dc:creator>
		<pubDate>Fri, 13 May 2011 07:15:12 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=218#comment-3398</guid>
		<description>the first example in the web page only writes to variable x? how to write and read using variable y and z?</description>
		<content:encoded><![CDATA[<p>the first example in the web page only writes to variable x? how to write and read using variable y and z?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sandeep Kumar</title>
		<link>http://www.codingunit.com/c-tutorial-binary-file-io/comment-page-1#comment-3261</link>
		<dc:creator>Sandeep Kumar</dc:creator>
		<pubDate>Sat, 26 Feb 2011 17:57:39 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=218#comment-3261</guid>
		<description>I want to store a character array data (89 bytes) to a binary file. Please send the fwrite function code for this. Is it possible to store current PC time to same binary file?

Thanks,
Sandeep</description>
		<content:encoded><![CDATA[<p>I want to store a character array data (89 bytes) to a binary file. Please send the fwrite function code for this. Is it possible to store current PC time to same binary file?</p>
<p>Thanks,<br />
Sandeep</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pratap</title>
		<link>http://www.codingunit.com/c-tutorial-binary-file-io/comment-page-1#comment-3210</link>
		<dc:creator>Pratap</dc:creator>
		<pubDate>Sat, 22 Jan 2011 01:07:28 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=218#comment-3210</guid>
		<description>I want to dump some memory into a file, a complex structure which contains pointers to list etc, and again want to set the same memory from this file.

Is it possible to do with fwrite &amp; fread functions</description>
		<content:encoded><![CDATA[<p>I want to dump some memory into a file, a complex structure which contains pointers to list etc, and again want to set the same memory from this file.</p>
<p>Is it possible to do with fwrite &amp; fread functions</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.codingunit.com/c-tutorial-binary-file-io/comment-page-1#comment-1980</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Thu, 09 Dec 2010 08:11:12 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=218#comment-1980</guid>
		<description>@radix: the goal of that example is to &lt;strong&gt;show how to use of the rewind() function&lt;/strong&gt;. That&#039;s why the end of the file is searched (otherwise there is nothing to rewind from) and then rewind() is called to go to first position of the file. 

You will get garbage if rewind isn&#039;t called because the for loop will try to read records beyond the end of the file, because there is no check performed to check if the end of the file has been reached. 

So again it&#039;s just to show the use of the rewind() function: nothing more, nothing less.  The search for the end of the file is only done, so we that we can rewind.</description>
		<content:encoded><![CDATA[<p>@radix: the goal of that example is to <strong>show how to use of the rewind() function</strong>. That&#8217;s why the end of the file is searched (otherwise there is nothing to rewind from) and then rewind() is called to go to first position of the file. </p>
<p>You will get garbage if rewind isn&#8217;t called because the for loop will try to read records beyond the end of the file, because there is no check performed to check if the end of the file has been reached. </p>
<p>So again it&#8217;s just to show the use of the rewind() function: nothing more, nothing less.  The search for the end of the file is only done, so we that we can rewind.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: radix</title>
		<link>http://www.codingunit.com/c-tutorial-binary-file-io/comment-page-1#comment-1975</link>
		<dc:creator>radix</dc:creator>
		<pubDate>Wed, 08 Dec 2010 15:25:13 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=218#comment-1975</guid>
		<description>In your last example you do the following...

fseek(ptr_myfile, sizeof(struct rec), SEEK_END);
rewind(ptr_myfile);

And mention that you get garbage without the rewind.  If you seek to the end of file and then offset beyond the end of the file, you will be reading garbage, you need a negative offset.  

These 2 lines are pointless in your example.  Or am I mistaken?</description>
		<content:encoded><![CDATA[<p>In your last example you do the following&#8230;</p>
<p>fseek(ptr_myfile, sizeof(struct rec), SEEK_END);<br />
rewind(ptr_myfile);</p>
<p>And mention that you get garbage without the rewind.  If you seek to the end of file and then offset beyond the end of the file, you will be reading garbage, you need a negative offset.  </p>
<p>These 2 lines are pointless in your example.  Or am I mistaken?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://www.codingunit.com/c-tutorial-binary-file-io/comment-page-1#comment-1796</link>
		<dc:creator>John</dc:creator>
		<pubDate>Fri, 06 Aug 2010 12:05:22 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=218#comment-1796</guid>
		<description>I&#039;ve seen people read 1 byte at a time, then if you need it to be one number just multiply it by it corresponding position...

first number  n*10000
+ second number n*1000
+ third number  n*100
+ forth number  n*10
+ fifth number  n..

I&#039;m not a professional so please research for better ways.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve seen people read 1 byte at a time, then if you need it to be one number just multiply it by it corresponding position&#8230;</p>
<p>first number  n*10000<br />
+ second number n*1000<br />
+ third number  n*100<br />
+ forth number  n*10<br />
+ fifth number  n..</p>
<p>I&#8217;m not a professional so please research for better ways.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

