<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Clinuxpro</title>
	<atom:link href="http://clinuxpro.com/feed" rel="self" type="application/rss+xml" />
	<link>http://clinuxpro.com</link>
	<description>Start learning Linux programming here</description>
	<lastBuildDate>Fri, 11 May 2012 05:34:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Bucket Hashing</title>
		<link>http://clinuxpro.com/bucket-hashing</link>
		<comments>http://clinuxpro.com/bucket-hashing#comments</comments>
		<pubDate>Sun, 06 May 2012 14:58:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Data structures]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1653</guid>
		<description><![CDATA[In the bucket hashing strategy, the hashing of a key does not yield the position of a single location, but of a storage area  in which several key entries can be stored. This storage area is called a bucket.]]></description>
			<content:encoded><![CDATA[<p>With the hash table stored on external storage, collisions imply  a lot of  i/o operations to search for a record.</p>
<p>In the bucket hashing strategy, the hashing of a key does not yield the position of a single location, but of a storage area  in which several key entries can be stored. This storage area is called a bucket. The file is divided in to a number of buckets. Each one has enough space to store multiple values. All key entries having matching hash values will be stored physically contiguously.</p>
<p>When a record has to be retrieved its key is hashed to give an offset this offset is a bucket offset, i.e. it gives the offset of a location where several records with the same hash value are stored. Then the bucket is read into internal memory and searched sequentially.</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/bucket-hashing/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chaining in Hashing</title>
		<link>http://clinuxpro.com/chaining-in-hashing</link>
		<comments>http://clinuxpro.com/chaining-in-hashing#comments</comments>
		<pubDate>Sun, 06 May 2012 14:53:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Data structures]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1649</guid>
		<description><![CDATA[Chaining method uses links (pointers) rather than a rehash  function. To resolve hash clashes. Two chaining techniques will be discussed, namely Coalesced chaining and Separate chaining.]]></description>
			<content:encoded><![CDATA[<p>Chaining method uses links (pointers) rather than a rehash  function. To resolve hash clashes. Two chaining techniques will be discussed, namely Coalesced chaining and Separate chaining.</p>
<h2><strong>Coalesced Chaining</strong></h2>
<p>The logic of this method completely eliminates the possibility that more than one collision will occur even for the same hash value.</p>
<p>It requires the storage area to be divided in to two parts</p>
<p>- a prime hash area<br />
- an overflow area</p>
<p>Initially, the hashing function is used to translate keys into location in the prime area. The first key value that hashes to a particular hash is thus placed in the prime area.</p>
<p>All subsequent keys which hash to the same value result I collision and are placed in the overflow area.</p>
<p>Links have to be established between key entries which hash to the same value it is because of this fact that each such entry requires a link field in addition to the key and data fields. if a node is not linked to any other node . it is given the familiar null value, indicating that there are no further key entries having the same hash value.</p>
<p>If the number of records grows beyond the number of available positions, they cannot be inserted without allocating more space. Hence too many locations are allocated initially, resulting in wasting of time in execution.</p>
<p>To reduce this wastage, the separate chaining method is used.</p>
<h2>Separate Chaining</h2>
<p>In this method, an array of header nodes is used. Each element in the array is a pointer which stores the address of a distinct linked list each linked list is a list of records whose keys have the same hash values. When a record has to be retrieved, the hashing function converts the given key to yield a position (subscript) in the array. The linked list which is initiated. I.e. pointed at by the header node at the subscript, is searched.</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/chaining-in-hashing/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rehashing</title>
		<link>http://clinuxpro.com/rehashing</link>
		<comments>http://clinuxpro.com/rehashing#comments</comments>
		<pubDate>Sun, 06 May 2012 14:42:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Data structures]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1647</guid>
		<description><![CDATA[This method involves using a secondary hash function, called a rehash function, on the hash value of the key. ]]></description>
			<content:encoded><![CDATA[<p>This method involves using a secondary hash function, called a <em><strong>rehash</strong></em> function, on the hash value of the key. When the location yielded by the hash function is found to be occupied by a different key during an insert or a search, in rehash function is used on the hash value to generate a new location. The rehash function is applied successively until an empty position is found. In general, the process of rehashing accepts one location and generates another by using a rehash function on the given location.<br />

<table id="wp-table-reloaded-id-46-no-1" class="wp-table-reloaded wp-table-reloaded-id-46">
<thead>
	<tr class="row-1 odd">
		<th class="column-1"><b>Location</b></th><th class="column-2"><b>Key</b></th><th class="column-3"><b>Data</b></th>
	</tr>
</thead>
<tbody>
	<tr class="row-2 even">
		<td class="column-1">0</td><td class="column-2">5</td><td class="column-3">aaa</td>
	</tr>
	<tr class="row-3 odd">
		<td class="column-1">1</td><td class="column-2">6</td><td class="column-3">bbb</td>
	</tr>
	<tr class="row-4 even">
		<td class="column-1">2</td><td class="column-2">7</td><td class="column-3">ccc</td>
	</tr>
	<tr class="row-5 odd">
		<td class="column-1">3</td><td class="column-2">8</td><td class="column-3">ddd</td>
	</tr>
	<tr class="row-6 even">
		<td class="column-1">4</td><td class="column-2"></td><td class="column-3"></td>
	</tr>
</tbody>
</table>
<br />
Assume that:</p>
<p>-The hashing function used is key mod5</p>
<p>-The rehashing function used is (key+1)mod5</p>
<p>-The key of the record to be inserted has value 12</p>
<p>The following table illustrates the methods by which rehashing handles collisions to find an empty location at which the record can be inserted.</p>

<table id="wp-table-reloaded-id-47-no-1" class="wp-table-reloaded wp-table-reloaded-id-47">
<thead>
	<tr class="row-1 odd">
		<th class="column-1">Key</th><th class="column-2">Hash/Rehash Function</th><th class="column-3">Location Generated</th><th class="column-4">Remarks</th>
	</tr>
</thead>
<tbody>
	<tr class="row-2 even">
		<td class="column-1">12</td><td class="column-2">Key mod 5</td><td class="column-3">2</td><td class="column-4">Already Occupied. So Rehash Function applied on location 2 to find an empty location.</td>
	</tr>
	<tr class="row-3 odd">
		<td class="column-1">2</td><td class="column-2">(Key + 1) mod 5</td><td class="column-3">3</td><td class="column-4">3 also occupied. Hence rehash on 3.</td>
	</tr>
	<tr class="row-4 even">
		<td class="column-1">3</td><td class="column-2">(Key + 1) mod 5</td><td class="column-3">4</td><td class="column-4">Since 4 is empty, record is inserted here.</td>
	</tr>
</tbody>
</table>

]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/rehashing/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hashing Collisions</title>
		<link>http://clinuxpro.com/hashing-collisions</link>
		<comments>http://clinuxpro.com/hashing-collisions#comments</comments>
		<pubDate>Sun, 06 May 2012 06:24:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Data structures]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1642</guid>
		<description><![CDATA[uppose that there are two keys such that their hash values are the same .Then the location at which the keys, and hence their corresponding records, have to be stored would be the same. Such a situation in which an attempt is made to store two keys at the same position is known as collision.]]></description>
			<content:encoded><![CDATA[<p>Hash tables and Indexes have one defect. Suppose that there are two keys such that their hash values are the same .Then the location at which the keys, and hence their corresponding records, have to be stored would be the same. Such a situation in which an attempt is made to store two keys at the same position is known as collision. The following example illustrates this concept.</p>
<p>Assume that the hashing function is</p>
<p><em><strong>Pos(key)= key%4</strong></em></p>
<p>Using this function on the keys 3,5,8 and 10 the keys get scattered  as shown below</p>
<div id="attachment_1660" class="wp-caption aligncenter" style="width: 310px"><a href="http://clinuxpro.com/hashing-collisions/hashingcollisions" rel="attachment wp-att-1660"><img class="size-medium wp-image-1660" title="Hashing Collisions" src="http://clinuxpro.com/wp-content/uploads/2012/05/Hashingcollisions-300x168.jpg" alt="Hashing Collisions" width="300" height="168" /></a><p class="wp-caption-text">Hashing Collisions</p></div>
<p>This looks fine, but a problem arises if the keys to be hashed are 3,4,8 and 10 as shown in the figure.</p>
<p>The keys 4 and 8 hash to the same position and these results in a collision</p>
<p>Irrespective of the hashing function used, collisions will occur. A good hashing function is one which minimizes collisions and spreads the records uniformly thought-out the available space</p>
<p><strong>Collision Processing:</strong></p>
<p>Clearly, two records cannot occupy the same position. Hence such a situation has to be taken care of. There are several methods of collision processing.</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/hashing-collisions/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Unbuffered I/O – The Unix Like File Routines</title>
		<link>http://clinuxpro.com/the-unbuffered-io-the-unix-like-file-routines</link>
		<comments>http://clinuxpro.com/the-unbuffered-io-the-unix-like-file-routines#comments</comments>
		<pubDate>Thu, 03 May 2012 03:42:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming]]></category>
		<category><![CDATA[File Handling in C]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1638</guid>
		<description><![CDATA[This is referred to as unbuffered I/O system because the programmer must provide and maintain all disk buffers, the routines do not do it automatically.]]></description>
			<content:encoded><![CDATA[<p>The buffered I/O system uses buffered input and output, that is, the operating system handles the details of data retrieval and storage, the system stores data temporarily (buffers it) in order to optimize file system access. The buffered I/O functions are handled directly as system calls without buffering by the operating system. That is why they are also known as low level functions. This is referred to as unbuffered I/O system because the programmer must provide and maintain all disk buffers, the routines do not do it automatically.</p>
<p>The low level functions are defined in the header file &lt;io.h&gt;.</p>
<p>These functions do not use file pointer of type FILE to access a particular file, but they use directly the file descriptors, as explained earlier, of type integer. They are also called handles.</p>
<p><strong>Opening and closing of files</strong></p>
<p>The function used to open a file is open( ). Its prototype is:</p>
<p><em><strong>int open(char *filename, int mode, int access);</strong></em></p>
<p>Here mode indicates one of the following macros defined in &lt;fcntl.h&gt;.</p>
<p><strong>Mode:</strong><br />
O_RDONLY  Read only<br />
O_WRONLY  Write only<br />
O_RDWR    Read / Write</p>
<p>The access parameter is used in UNIX environment for providing the access to particular users and is just included here for compatibility and can be set to zero.</p>
<p>open() function returns –1 on failure. It is used as:</p>
<p><strong>Code fragment</strong><br />
int fd;<br />
if ((fd=open(filename,mode,0)) == -1)<br />
{ printf(“cannot open file\n”);<br />
exit(1); }</p>
<p>If the file does not exist, open() the function will not create it. For this, the function creat() is used which will create new files and re-write old ones. The prototype is:</p>
<p><em><strong>int creat(char *filename, int access);</strong></em></p>
<p>It returns a file descriptor; if successful else it returns –1. It is not an error to create an already existing file, the function will just truncate its length to zero. The access parameter is used to provide permissions to the users in the UNIX environment.</p>
<p>The function close() is used to close a file. The prototype is:</p>
<p><em><strong>int close(int fd);</strong></em></p>
<p>It returns zero if successful and –1 if not.</p>
<p><strong>Reading, Writing and Positioning in File</strong></p>
<p>The functions read() and write() are used to read from and write to a file. Their prototypes are:</p>
<p><em><strong>int read(int fd, void *buf, int size);</strong></em><br />
<em><strong>int write(int fd, void *buf, int size);</strong></em></p>
<p>The first parameter is the file descriptor returned by open(), the second parameter holds the data which must be typecast to the format needed by the program, the third parameter indicates the number of bytes to transferred. The return value tells how<br />
many bytes are actually transferred. If this value is –1, then an error must have occurred.</p>
<p><strong>Example</strong><br />
Write a program to copy one file to another to illustrate the use of the above functions. The program should expect two command line arguments indicating the name of the file to be copied and the name of the file to be created.</p>
<pre class="brush: c">
/* Program to copy one file to another file to illustrate the functions*/
# include&lt;stdio.h&gt;
# include&lt;io.h&gt;
#include&lt;process.h&gt;
typedef char arr[80];
typedef char name[30];
main()
{
arr buf;
name fname, sname;
int fd1,fd2,size;
/* check for the command line arguments */
if (argc!=3)
{ printf(&quot;Invalid number of arguments\n&quot;);
exit(0);
}
if ((fd1=open(argv[1],O_RDONLY))&lt;0)
{ printf(&quot;Error in opening file %s \n&quot;,argv[1]);
exit(0);
}
if ((fd2=creat(argv[2],0))&lt;0)
{ printf(&quot;Error in creating file %s \n&quot;,argv[2]);
exit(0);}
open(argv[2],O_WRONLY);
size=read(fd1,buf,80); /* read till end of file */
while (size&gt;0)
{ write(fd2,buf,80);
size=read(fd1,buf,80);
}
close(fd1);
close(fd2);
} </pre>
<p><strong>OUTPUT</strong><br />
If the number of arguments given on the command line is not correct then output would be:<br />
Invalid number of arguments<br />
One file is opened in the read mode, and another file is opened in the write mode. The output would be as follows is the file to be read is not present (let the file be f1.dat):<br />
Error in opening file f1.dat<br />
The output would be as follows if the disk is full and the file cannot be created (let the output file be f2.dat):<br />
Error in creating file f2.dat<br />
If there is no error contents of f1.dat will be copied to f2.dat.</p>
<p><strong>lseek()</strong></p>
<p>The function lseek() is provided to move to the specific position in a file. Its prototype is:</p>
<p><em><strong>long lseek(int fd, long offset, int pos);</strong></em></p>
<p>This function is exactly the same as fseek() except that the file descriptor is used instead of the file pointer.</p>
<p>Using the above defined functions, it is possible to write any kind of program dealing with files.</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/the-unbuffered-io-the-unix-like-file-routines/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Positioning the File Pointer</title>
		<link>http://clinuxpro.com/positioning-the-file-pointer</link>
		<comments>http://clinuxpro.com/positioning-the-file-pointer#comments</comments>
		<pubDate>Thu, 03 May 2012 02:49:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming]]></category>
		<category><![CDATA[File Handling in C]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1636</guid>
		<description><![CDATA[To support random access files, C requires a function with the help of which the file pointer can be positioned at any random location in the file.]]></description>
			<content:encoded><![CDATA[<p>To support random access files, C requires a function with the help of which the file pointer can be positioned at any random location in the file. Such a function defined in the standard library is discussed below:</p>
<p>The function fseek( ) is used to set the file position. Its prototype is:</p>
<p><em><strong>int fseek(FILE *fp, long offset, int pos);</strong></em></p>
<p>The first argument is the pointer to a file. The second argument is the number of bytes to move the file pointer, counting from zero. This argument can be positive, negative or zero depending on the desired movement. The third parameter is a flag indicating from where in the file to compute the offset. It can have three values:</p>
<p><em><strong>SEEK_SET(or value 0) the beginning of the file,</strong></em><br />
<em><strong>SEEK_CUR(or value 1) the current position and</strong></em><br />
<em><strong>SEEK_END(or value 2) the end of the file</strong></em></p>
<p>These three constants are defined in &lt;stdio.h&gt;. If successful fseek( ) returns zero. Another function rewind() is used to reset the file position to the beginning of the file.</p>
<p>Its prototype is:</p>
<p><em><strong>void rewind(FILE *fp);</strong></em></p>
<p>A call to rewind is equivalent to the call</p>
<p><em><strong>fseek(fp,0,SEEK_SET);</strong></em></p>
<p>Another function ftell() is used to tell the position of the file pointer. Its prototype is:</p>
<p><em><strong>long ftell(FILE *fp);</strong></em></p>
<p>It returns –1 on error and the position of the file pointer if successful.</p>
<p><strong>Example</strong><br />
Write a program to search a record in an already created file and update it.</p>
<pre class="brush: c">
/*Program to search a record in an already created file*/
#include&lt;stdio.h&gt;
#include&lt;stdio.h&gt;
#include&lt;process.h&gt;
#include&lt;string.h&gt;
void main()
{
int r,found;
struct stud
{
char name[30];
int age;
int roll_no;
}st;
FILE *fp;
/* open the file in read/write mode */
if((fp=fopen(&quot;f1.dat&quot;,&quot;r+b&quot;))==NULL)
{ printf(&quot;Error while opening the file \n&quot;);
exit(0);
}
/* Get the roll_no of the student */
printf(&quot;Enter the roll_no of the record to be updated\n&quot;);
found=0;
scanf(&quot;%d&quot;,&amp;r);
/* check in the file for the existence of the roll_no */
while((!feof(fp)) &amp;&amp; !(found))
{ fread(&amp;st,sizeof(stud),1,fp);
if(st.roll_no == r)
/* if roll_no is found then move one record backward to update it */
{ fseek(fp,- sizeof(stud),SEEK_CUR);
printf(&quot;Enter the new name\n&quot;);
scanf(&quot;%s&quot;,st.name);
fwrite(fp,sizeof(stud),1,fp);
found=1;
}
}
if (!found)
printf(&quot;Record not present\n&quot;);
fclose(fp);
}</pre>
<p><strong>OUTPUT</strong><br />
Let the input file be as follows:<br />
Geeta 18  101<br />
Leena 17  102<br />
Mahesh 23 103<br />
Lokesh 21 104<br />
Amit 19  105</p>
<p>Let the roll_no of the record to be updated be 106. Now since this roll_no is not present the output would be:</p>
<p>Record not present</p>
<p>If the roll_no to be searched is 103, then if the new name is Sham, the output would be the file with the contents:</p>
<p>Geeta 18  101<br />
Leena 17  102<br />
Sham  23  103<br />
Lokesh 21 104<br />
Amit   19 105</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/positioning-the-file-pointer/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sequential Vs Random access Files</title>
		<link>http://clinuxpro.com/sequential-vs-random-access-files</link>
		<comments>http://clinuxpro.com/sequential-vs-random-access-files#comments</comments>
		<pubDate>Thu, 03 May 2012 02:12:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming]]></category>
		<category><![CDATA[File Handling in C]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1634</guid>
		<description><![CDATA[Difference between Sequential and Random access Files]]></description>
			<content:encoded><![CDATA[<p><strong>Difference between Sequential and Random access Files</strong></p>
<p>C supports two type of files – text and binary files, also two types of file systems – buffered and unbuffered file system. We can also differentiate in terms of the type of file access as Sequential access files and random access files. Sequential access files allow reading the data from the file in sequential manner which means that data can only be read in sequence.</p>
<p>Random access files allow reading data from any location in the file. To achieve this purpose, C defines a set of functions to manipulate the position of the file pointer.</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/sequential-vs-random-access-files/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Block Input/Output Functions</title>
		<link>http://clinuxpro.com/block-inputoutput-functions</link>
		<comments>http://clinuxpro.com/block-inputoutput-functions#comments</comments>
		<pubDate>Thu, 03 May 2012 01:57:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming]]></category>
		<category><![CDATA[File Handling in C]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1632</guid>
		<description><![CDATA[Block Input / Output functions read/write a block (specific number of bytes from/to a file. A block can be a record, a set of records or an array.]]></description>
			<content:encoded><![CDATA[<p>Block Input / Output functions read/write a block (specific number of bytes from/to a file. A block can be a record, a set of records or an array. These functions are also defined in standard library and are described below.</p>
<p><em><strong>• fread( )</strong></em><br />
<em><strong>• fwrite( )</strong></em></p>
<p>These two functions allow reading and writing of blocks of data. Their syntax is:</p>
<p><em><strong>int fread(void *buf, int num_bytes, int count, FILE *fp);</strong></em><br />
<em><strong>int fwrite(void *buf, int num_bytes, int count, FILE *fp);</strong></em></p>
<p>In case of fread(), buf is the pointer to a memory area that receives the data from the file and in fwrite(), it is the pointer to the information to be written to the file.num_bytes specifies the number of bytes to be read or written. These functions are quite helpful in case of binary files. Generally these functions are used to read or write array of records from or to a file. The use of the above functions is shown in the following program.</p>
<p><strong>Example</strong><br />
Write a program using fread( ) and fwrite() to create a file of records and then read and print the same file.</p>
<pre class="brush: c">
/* Program to illustrate the fread() and fwrite() functions*/
#include&lt;stdio.h&gt;
#include&lt;conio.h&gt;
#include&lt;process.h&gt;
#include&lt;string.h&gt;
void main()
{
struct stud
{
char name[30];
int age;
int roll_no;
}s[30],st;
int i;
FILE *fp;
/*opening the file in write mode*/
if((fp=fopen(&quot;sud.dat&quot;,&quot;w&quot;))== NULL)
{ printf(&quot;Error while creating a file\n&quot;);
exit(0); }
/* reading an array of students */
for(i=0;i&lt;30;i++)
scanf(&quot;%s %d %d&quot;,s[i].name,s[i].age,s[i].roll_no);
/* writing to a file*/
fwrite(s,sizeof(struct stud),30,fp);
fclose(fp);
/* opening a file in read mode */
fp=fopen(&quot;stud.dat&quot;,&quot;r&quot;);
/* reading from a file and writing on the screen */
while(!feof(fp))
{
fread(&amp;st,sizeof(struct stud),1,fp);
fprintf(&quot;%s %d %d&quot;,st.name,st.age,st.roll_no);
}
fclose(fp);
}</pre>
<p><strong>OUTPUT</strong><br />
This program reads 30 records (name, age and roll_number) from the user, writes one record at a time to a file. The file is closed and then reopened in read mode; the records are again read from the file and written on to the screen.</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/block-inputoutput-functions/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Formatted Input/Output Functions</title>
		<link>http://clinuxpro.com/formatted-inputoutput-functions</link>
		<comments>http://clinuxpro.com/formatted-inputoutput-functions#comments</comments>
		<pubDate>Thu, 03 May 2012 01:51:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming]]></category>
		<category><![CDATA[File Handling in C]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1629</guid>
		<description><![CDATA[C provides a set of formatted input/output functions. These are defined in standard library and are discussed here fscanf() and fprintf().
]]></description>
			<content:encoded><![CDATA[<p>If the file contains data in the form of digits, real numbers, characters and strings, then character input/output functions are not enough as the values would be read in the form of characters. Also if we want to write data in some specific format to a file, then it is not possible with the above described functions. Hence C provides a set of formatted input/output functions. These are defined in standard library and are discussed below:</p>
<p><strong>fscanf()</strong> and <em><strong>fprintf()</strong></em></p>
<p>These functions are used for formatted input and output. These are identical to scanf() and printf() except that the first argument is a file pointer that specifies the file to be read or written, the second argument is the format string. The syntax for these functions is:</p>
<p><em><strong>int fscanf(FILE *fp, char *format,. . .);</strong></em><br />
<em><strong>int fprintf(FILE *fp, char *format,. . .);</strong></em></p>
<p>Both these functions return an integer indicating the number of bytes actually read or written.</p>
<p><strong>Example</strong><br />
Write a program to read formatted data (account number, name and balance) from a file and print the information of clients with zero balance, in formatted manner on the screen.</p>
<pre class="brush: c">
/* Program to read formatted data from a file */
#include&lt;stdio.h&gt;
main()
{
int account;
char name[30];
double bal;
FILE *fp;
if((fp=fopen(&quot;bank.dat&quot;,&quot;r&quot;))== NULL)
printf(&quot;FILE not present \n&quot;);
else
do{
fscanf(fp,&quot;%d%s%lf&quot;,&amp;account,name,&amp;bal);
if(!feof(fp))
{
if(bal==0)
printf(&quot;%d %s %lf\n&quot;,account,name,bal);
}
}while(!feof(fp));
}</pre>
<p><strong>OUTPUT</strong><br />
This program opens a file “bank.dat” in the read mode if it exists, reads the records and prints the information (account number, name and balance) of the zero balance records.</p>
<p>Let the file be as follows:</p>
<p>101 nuj    1200<br />
102 Raman  1500<br />
103 Swathi 0<br />
104 Ajay   1600<br />
105 Udit   0</p>
<p>The output would be as follows:<br />
103 Swathi 0<br />
105 Udit   0</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/formatted-inputoutput-functions/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hash Tables</title>
		<link>http://clinuxpro.com/hash-tables</link>
		<comments>http://clinuxpro.com/hash-tables#comments</comments>
		<pubDate>Tue, 01 May 2012 09:31:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Data structures]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1623</guid>
		<description><![CDATA[Hash Tables method eliminates the use of the index file completely the only file used is the data file which is known as the hash table.]]></description>
			<content:encoded><![CDATA[<p><strong>Hash Tables</strong> method eliminates the use of the index file completely the only file used is the data file which is known as the <em>hash table.</em></p>

<table id="wp-table-reloaded-id-45-no-1" class="wp-table-reloaded wp-table-reloaded-id-45">
<thead>
	<tr class="row-1 odd">
		<th class="column-1">Offset</th><th class="column-2">Key</th><th class="column-3">Data</th>
	</tr>
</thead>
<tbody>
	<tr class="row-2 even">
		<td class="column-1">0</td><td class="column-2">6</td><td class="column-3">aaa</td>
	</tr>
	<tr class="row-3 odd">
		<td class="column-1">10</td><td class="column-2">4</td><td class="column-3">bbb</td>
	</tr>
	<tr class="row-4 even">
		<td class="column-1">20</td><td class="column-2">1</td><td class="column-3">ccc</td>
	</tr>
	<tr class="row-5 odd">
		<td class="column-1">30</td><td class="column-2">5</td><td class="column-3">ddd</td>
	</tr>
	<tr class="row-6 even">
		<td class="column-1">40</td><td class="column-2">2</td><td class="column-3">eee</td>
	</tr>
	<tr class="row-7 odd">
		<td class="column-1">50</td><td class="column-2">3</td><td class="column-3">fff</td>
	</tr>
</tbody>
</table>

<p>This approach also involves calculation of a location based on the value of a key, however, instead of inserting a key–offset pair into an index as in the previous method, a whole record is inserted into the calculated position in the data file, i.e., the hash table</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/hash-tables/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hash Indexes</title>
		<link>http://clinuxpro.com/hash-indexes</link>
		<comments>http://clinuxpro.com/hash-indexes#comments</comments>
		<pubDate>Tue, 01 May 2012 08:51:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Data structures]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1619</guid>
		<description><![CDATA[An index created by placing keys in locations calculated using a hashing function is called a hash index file.]]></description>
			<content:encoded><![CDATA[<p>An index created by placing keys in locations calculated using a hashing function is called a <em><strong>hash index</strong></em> file. It contains a <em><strong>key–offset pair</strong></em> corresponding to each record I the data file.</p>
<p>In the technique employing hash indexes, two files are used:</p>
<p>- A file containing the data records, and</p>
<p>- A hash index file</p>
<p><strong>
<table id="wp-table-reloaded-id-44-no-1" class="wp-table-reloaded wp-table-reloaded-id-44">
<thead>
	<tr class="row-1 odd">
		<th colspan="3" class="column-1 colspan-3">Hash Index File</th><th class="column-4">Offset</th><th colspan="2" class="column-5 colspan-2">Data File</th>
	</tr>
</thead>
<tbody>
	<tr class="row-2 even">
		<td class="column-1">Location</td><td class="column-2">Key</td><td class="column-3">Offset</td><td class="column-4"></td><td class="column-5">Key</td><td class="column-6">Data</td>
	</tr>
	<tr class="row-3 odd">
		<td class="column-1">0</td><td class="column-2">3</td><td class="column-3">50</td><td class="column-4">0</td><td class="column-5">6</td><td class="column-6">aaa</td>
	</tr>
	<tr class="row-4 even">
		<td class="column-1">1</td><td class="column-2">4</td><td class="column-3">10</td><td class="column-4">10</td><td class="column-5">4</td><td class="column-6">bbb</td>
	</tr>
	<tr class="row-5 odd">
		<td class="column-1">2</td><td class="column-2">5</td><td class="column-3">30</td><td class="column-4">20</td><td class="column-5">1</td><td class="column-6">ccc</td>
	</tr>
	<tr class="row-6 even">
		<td class="column-1">3</td><td class="column-2">6</td><td class="column-3">0</td><td class="column-4">30</td><td class="column-5">5</td><td class="column-6">ddd</td>
	</tr>
	<tr class="row-7 odd">
		<td class="column-1">4</td><td class="column-2">1</td><td class="column-3">20</td><td class="column-4">40</td><td class="column-5">2</td><td class="column-6">eee</td>
	</tr>
	<tr class="row-8 even">
		<td class="column-1">5</td><td class="column-2">2</td><td class="column-3">40</td><td class="column-4">50</td><td class="column-5">3</td><td class="column-6">fff</td>
	</tr>
</tbody>
</table>
</strong></p>
<p>- The records in the data files exist in random order.</p>
<p>- The hash index file stores the key value and offset of every record.</p>
<p>- Given key, the offset of the record corresponding to it calculated as follows.</p>
<p>- A hashing function is used to calculate the location of the key-offset pair in the hash index file.</p>
<p>- The offset part is then used to retrieve  the record form the file .</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/hash-indexes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hashing Functions</title>
		<link>http://clinuxpro.com/hashing-functions</link>
		<comments>http://clinuxpro.com/hashing-functions#comments</comments>
		<pubDate>Thu, 26 Apr 2012 13:25:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Data structures]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1616</guid>
		<description><![CDATA[Conversion of the key to an address is done by a relation (formula) which is known as a hashing function.]]></description>
			<content:encoded><![CDATA[<p>Conversion of the key to an address is done by a relation (formula) which is known as a hashing function. A hashing function is actually just a relation which operates on a key to give its hash value (a number) it converts a key to yield a location (position) at which the record should be found.</p>
<p>This is known as a key to address transformation.</p>
<p>Hence the process of generating the location of a record using a hash function can be summarized as:</p>
<ul>
<li>Given a key the hash function converts it into a hash value within in the range 1-n ; where n is the size of the storage (address) space that has been allocated for the records</li>
</ul>
<ul>
<li>The record is then retrieved at the location generated</li>
</ul>
<p>Two hashing techniques commonly employed will be</p>
<ul>
<li>Hash indexes</li>
<li>Hash Tables</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/hashing-functions/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hashing</title>
		<link>http://clinuxpro.com/hashing</link>
		<comments>http://clinuxpro.com/hashing#comments</comments>
		<pubDate>Thu, 26 Apr 2012 12:49:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Data structures]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1611</guid>
		<description><![CDATA[The fundamental principle of hashing is converting a key to an address to retrieve a record. Its main purpose is to eliminate unnecessary searching by using the method of direct addressing and thus cutting down search time.]]></description>
			<content:encoded><![CDATA[<p><strong>Organizing  Data for Retrieval</strong></p>
<p>Retrieval of data involves searching the file for the required data. In order to make the search as efficient as possible it is important to property organize the data at the time of storing it.</p>
<p>As we have already seen, two methods of organizing data are:</p>
<ul>
<li>Organising  the records in the data file itself, by storing it on the basis of a key  and</li>
<li>Creating and using an index for retrieval</li>
</ul>
<p>However in spite of organizing the data well, it would still be necessary to scan through some keys in order to find a record. This process is time consuming optimally, we would like to have an organization in which there are no unnecessary comparisons or searches and by which each key can be retrieved in a single access .This is made possible to a certain by concept known as <strong>hashing.</strong></p>
<h2>Hashing</h2>
<p>To understand the concept of <em>hashing</em> let us look at the various ways of retrieving record.</p>
<p>One method of retrieving the desired record would be to search through the file. But this method is time consuming and slow, especially if the file is very large.</p>
<p>Instead, if there was some method by which we could get to know the offset (relative address of the record from the beginning of the file) retrieval would be vary fast.  Given   the offset of a record, it could easily be retrieving in a single disk access without wasting time in searching.</p>
<p>Let us see if such a method of obtaining the offset is feasible.</p>
<p>As an example assume that the keys in a file are consecutive numbers starting from 0. Then given a key the offset of the record corresponding to it can be easily calculated by the formula.</p>
<p><em><strong>Key *   Record length</strong></em></p>
<p>From the above discussion, one can conclude that there does seem to be a method by which the offset can be calculated.</p>
<p>Ideally all key values must begin at 0 and sequentially increase in step of 1. So that given a key the offset can be calculated and the record retrieved in a single disk aces thus eliminating searching. But keys have to be more meaningful thing just consecutive integral numbers.  Fields like client codes product codes and even names are more likely to be used as keys.</p>
<p>For instance a situation might occur in an inventory application where product codes are numbered starting from 10,000 instead of 0. On reflection, it becomes clear that even this is an almost ideal situation since for any given product code, the corresponding key can easily be found at the position given by the relation.</p>
<p>Let us summaries what has been done so far.</p>
<p>A record in a file has to be retrieved.  Hence its offset has to be calculated this is done by converting the key of the record to derive a location which yields the offset of the record. This is the fundamental principle of hashing, i.e. converting a key to an address to retrieve a record. Its main purpose is to eliminate unnecessary searching by using the method of direct addressing and thus cutting down search time. It offers one of the best methods of finding information associated with a unique identifying key.</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/hashing/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>String Input/Output Functions</title>
		<link>http://clinuxpro.com/string-inputoutput-functions</link>
		<comments>http://clinuxpro.com/string-inputoutput-functions#comments</comments>
		<pubDate>Thu, 26 Apr 2012 10:52:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming]]></category>
		<category><![CDATA[File Handling in C]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1609</guid>
		<description><![CDATA[C provides some string input/output functions with the help of which we can read/write a set of characters at one time.]]></description>
			<content:encoded><![CDATA[<p>If we want to read a whole line in the file then each time we will need to call character input function, instead C provides some string input/output functions with the help of which we can read/write a set of characters at one time. These are defined in the standard library and are discussed below:</p>
<p><em><strong>• fgets( )</strong></em><br />
<em><strong>• fputs( )</strong></em></p>
<p>These functions are used to read and write strings. Their syntax is:</p>
<p><em><strong>int fputs(char *str, FILE *stream);</strong></em><br />
<em><strong>char *fgets(char *str, int num, FILE *stream);</strong></em></p>
<p>The integer parameter in fgets( ) is used to indicate that at most num-1 characters are to be read, terminating at end-of-file or end-of-line. The end-of-line character will be placed in the string str before the string terminator, if it is read. If end-of-file is encountered as the first character, EOF is returned, otherwise str is returned. The fputs( ) function returns a non-negative number or EOF if unsuccessful.</p>
<p><strong>Example</strong><br />
Write a program read a file and count the number of lines in the file, assuming that a line can contain at most 80 characters.</p>
<pre class="brush: c">
/*Program to read a file and count the number of lines in the file */
#include&lt;stdio.h&gt;
#include&lt;conio.h&gt;
#include&lt;process.h&gt;
void main()
{
FILE *fp;
int cnt=0;
char str[80];
/* open a file in read mode */
if ((fp=fopen(&quot;lines.dat&quot;,&quot;r&quot;))== NULL)
{ printf(&quot;File does not exist\n&quot;);
exit(0);
}
/* read the file till end of file is encountered */
while(!(feof(fp)))
{ fgets(str,80,fp);
/*reads at most 80 characters in str */
cnt++;
/* increment the counter after reading a line */
}
}/* print the number of lines */
printf(“The number of lines in the file is :%d\n”,cnt);
fclose(fp);
}</pre>
<p><strong>OUTPUT</strong><br />
Let us assume that the contents of the file “lines.dat” are as follows:<br />
This is C programming.<br />
I love C programming.<br />
To be a good programmer one should have a good logic. This is a must.<br />
C is a procedural programming language.<br />
After the execution the output would be:<br />
The number of lines in the file is: 4</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/string-inputoutput-functions/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Character Input and Output in Files</title>
		<link>http://clinuxpro.com/character-input-and-output-in-files</link>
		<comments>http://clinuxpro.com/character-input-and-output-in-files#comments</comments>
		<pubDate>Thu, 26 Apr 2012 10:36:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming]]></category>
		<category><![CDATA[File Handling in C]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1603</guid>
		<description><![CDATA[ANSI C provides a set of functions for reading and writing character by character or one byte at a time. These functions are defined in the standard library.]]></description>
			<content:encoded><![CDATA[<p>ANSI C provides a set of functions for reading and writing character by character or one byte at a time. These functions are defined in the standard library. They are listed and described below:</p>
<p><strong>• getc( )</strong><br />
<strong>• putc( )</strong></p>
<p>getc( ) is used to read a character from a file and putc( ) is used to write a character to a file. Their syntax is as follows:</p>
<p><em><strong>int putc(int ch, FILE *stream);</strong></em><br />
<em><strong>int getc(FILE *stream);</strong></em></p>
<p>The file pointer indicates the file to read from or write to. The character ch is formally called an integer in putc( ) function but only the low order byte is used. On success putc( ) returns a character(in integer form) written or EOF on failure. Similarly getc( ) returns an integer but only the low order byte is used. It returns EOF when end-of-file is reached. getc( ) and putc( ) are defined in &lt;stdio.h&gt; as macros not functions.</p>
<h2>fgetc( ) and fputc( )</h2>
<p>Apart from the above two macros, C also defines equivalent functions to read / write characters from / to a file. These are:</p>
<p><em><strong>int fgetc(FILE *stream);</strong></em><br />
<em><strong>int fputc(int c, FILE *stream);</strong></em></p>
<p>To check the end of file, C includes the function feof( ) whose prototype is:<br />
<em><strong>int feof(FILE *fp);</strong></em><br />
It returns 1 if end of file has been reached or 0 if not. The following code fragment explains the use of these functions.</p>
<p><strong>Example</strong><br />
Write a program to copy one file to another.</p>
<pre class="brush: c">
/*Program to copy one file to another */
#include &lt;stdio.h&gt;
main( )
{
FILE *fp1;
FILE *fp2;
int ch;
if((fp1=fopen(“f1.dat”,”r”)) == NULL)
{
printf(“Error opening input file\n”);
exit(0);
}
if((fp2=fopen(“f2.dat”,”w”)) == NULL)
{
printf(“Error opening output file\n”);
exit(0);
}
while (!feof(fp1))
{
ch=getc(fp1);
putc(ch,fp2);
}
fclose(fp1);
fclose(fp2);
}</pre>
<p><strong>OUTPUT</strong>:<br />
If the file ”f1.dat” is not present, then the output would be:<br />
Error opening input file<br />
If the disk is full, then the output would be:<br />
Error opening output file<br />
If there is no error, then “f2.dat” would contain whatever is present in “f1.dat” after the execution of the program, if “f2.dat” was not empty earlier, then its contents would be overwritten.</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/character-input-and-output-in-files/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Input and Output Using File Pointers</title>
		<link>http://clinuxpro.com/input-and-output-using-file-pointers</link>
		<comments>http://clinuxpro.com/input-and-output-using-file-pointers#comments</comments>
		<pubDate>Thu, 26 Apr 2012 10:25:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming]]></category>
		<category><![CDATA[File Handling in C]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1600</guid>
		<description><![CDATA[There are several functions and macros defined in <stdio.h> header file for reading and writing the file. ]]></description>
			<content:encoded><![CDATA[<p>After opening the file, the next thing needed is the way to read or write the file. There are several functions and macros defined in <em><strong>&lt;stdio.h&gt;</strong></em> header file for reading and writing the file. These functions can be categorized according to the form and type of data read or written on to a file. These functions are classified as:</p>
<p>• Character input/output functions.<br />
• String input/output functions.<br />
• Formatted input/output functions.<br />
• Block input/output functions.</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/input-and-output-using-file-pointers/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>fclose( )</title>
		<link>http://clinuxpro.com/fclose</link>
		<comments>http://clinuxpro.com/fclose#comments</comments>
		<pubDate>Thu, 26 Apr 2012 06:46:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming]]></category>
		<category><![CDATA[File Handling in C]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1593</guid>
		<description><![CDATA[When the processing of the file is finished, the file should be closed using the fclose() function, whose syntax is: int fclose(FILE *fptr);]]></description>
			<content:encoded><![CDATA[<p><strong>Close A File Using The Function fclose( )</strong></p>
<p>When the processing of the file is finished, the file should be closed using the fclose() function, whose syntax is:</p>
<p><em><strong>int fclose(FILE *fptr);</strong></em></p>
<p>This function flushes any unwritten data for stream, discards any unread buffered input, frees any automatically allocated buffer, and then closes the stream. The return value is 0 if the file is closed successfully or a constant EOF, an end-of file marker, if an error occurred. This constant is also defined in &lt;stdio.h&gt;. If the function fclose() is not called explicitly, the operating system normally will close the file when the program execution terminates.</p>
<p>The following code fragment explains how to close a file.</p>
<pre class="brush: c">
# include &lt;stdio.h&gt;
main ( )
{
FILE *fp;
if ((fp=fopen(“file1.dat”, “r”))==NULL)
{
printf(“FILE DOES NOT EXIST\n”);
exit(0);
}
.................
.................
.................
................
/* close the file */
fclose(fp);
}</pre>
<p>Once the file is closed, it cannot be used further. If required it can be opened in same or another mode.</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/fclose/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>fopen( )</title>
		<link>http://clinuxpro.com/fopen</link>
		<comments>http://clinuxpro.com/fopen#comments</comments>
		<pubDate>Thu, 26 Apr 2012 06:33:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming]]></category>
		<category><![CDATA[File Handling in C]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1589</guid>
		<description><![CDATA[The fopen() function opens a stream for use and links a file with that stream. This function returns a file pointer, described in the previous section. The syntax is as follows: FILE *fopen(char *filename,*mode);]]></description>
			<content:encoded><![CDATA[<p><strong>Open A File Using The Function fopen( )</strong></p>
<p>Once a file pointer variables has been declared, the next step is to open a file. The fopen() function opens a stream for use and links a file with that stream. This function returns a file pointer, described in the previous section. The syntax is as follows:</p>
<p><strong>FILE<em> *fopen(char *filename,*mode);</em></strong></p>
<p>where mode is a string, containing the desired open status. The filename must be a string of characters that provide a valid file name for the operating system and may include a path specification. The legal mode strings are shown below in the table:</p>
<p><strong>Legal values to the fopen( ) mode parameter</strong><br />

<table id="wp-table-reloaded-id-43-no-1" class="wp-table-reloaded wp-table-reloaded-id-43">
<thead>
	<tr class="row-1 odd">
		<th class="column-1"><b>Mode</b></th><th class="column-2"><b>Meaning</b></th>
	</tr>
</thead>
<tbody>
	<tr class="row-2 even">
		<td class="column-1">“r” / “rt”<br />
</td><td class="column-2">opens a text file for read only access<br />
</td>
	</tr>
	<tr class="row-3 odd">
		<td class="column-1">“w” / “wt”</td><td class="column-2">creates a text file for write only access</td>
	</tr>
	<tr class="row-4 even">
		<td class="column-1">“a” / “at”</td><td class="column-2">text file for appending to a file</td>
	</tr>
	<tr class="row-5 odd">
		<td class="column-1">“r+t”</td><td class="column-2">open a text file for read and write access<br />
</td>
	</tr>
	<tr class="row-6 even">
		<td class="column-1">“w+t”<br />
<br />
</td><td class="column-2">creates a text file for read and write access,<br />
<br />
</td>
	</tr>
	<tr class="row-7 odd">
		<td class="column-1">“a+t”</td><td class="column-2">opens or creates a text file and read access</td>
	</tr>
	<tr class="row-8 even">
		<td class="column-1">“rb”<br />
<br />
</td><td class="column-2">opens a binary file for read only access<br />
<br />
</td>
	</tr>
	<tr class="row-9 odd">
		<td class="column-1">“wb”</td><td class="column-2">create a binary file for write only access</td>
	</tr>
	<tr class="row-10 even">
		<td class="column-1">“ab”<br />
</td><td class="column-2">binary file for appending to a file<br />
<br />
</td>
	</tr>
	<tr class="row-11 odd">
		<td class="column-1">“r+b”<br />
</td><td class="column-2">opens a binary or read and write access</td>
	</tr>
	<tr class="row-12 even">
		<td class="column-1">“w+b”<br />
<br />
</td><td class="column-2">creates a binary or read and write access,<br />
<br />
</td>
	</tr>
	<tr class="row-13 odd">
		<td class="column-1">“a+b”</td><td class="column-2">open or binary file and read access</td>
	</tr>
</tbody>
</table>
</p>
<p>The following code fragment explains how to open a file for reading.<br />
<strong></strong>
<pre class="brush: c">
#include &lt;stdio.h&gt;
main ()
{
FILE *fp;
if ((fp=fopen(“file1.dat”, “r”))==NULL)
{
printf(“FILE DOES NOT EXIST\n”);
exit(0);
}
}
</pre>
<p>The value returned by the fopen( ) function is a file pointer. If any error occurs while opening the file, the value of this pointer is NULL, a constant declared in &lt;stdio.h&gt;. Always check for this possibility as shown in the above example.</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/fopen/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>File Pointer</title>
		<link>http://clinuxpro.com/file-pointer</link>
		<comments>http://clinuxpro.com/file-pointer#comments</comments>
		<pubDate>Thu, 26 Apr 2012 06:22:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming]]></category>
		<category><![CDATA[File Handling in C]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1586</guid>
		<description><![CDATA[To access any file, we need to declare a pointer to FILE structure and then associate it with the particular file. This pointer is referred as a file pointer and it is declared as follows: FILE *fp;]]></description>
			<content:encoded><![CDATA[<p>A sequential stream of bytes ending with an <em>end-of-file</em> marker is what is called a <em><strong>file.</strong></em> When the file is opened the stream is associated with the file. By default, three files and their streams are automatically opened when program execution begins &#8211; <strong>the standard input, standard output,</strong> and the <strong>standard error</strong>. Streams provide communication channels between files and programs.</p>
<p>For example, the standard input stream enables a program to read data from the keyboard, and the standard output stream enables to write data on the screen. Opening a file returns a pointer to a FILE structure (defined in &lt;stdio.h&gt;) that contains information, such as size, current file pointer position, type of file etc., to perform operations on the file. This structure also contains an integer called a file descriptor which is an index into the table maintained by the operating system namely, the open file table. Each element of this table contains a block called file control block (FCB) used by the operating system to administer a particular file.</p>
<p>The standard input, standard output and the standard error are manipulated using file pointers stdin, stdout and stderr. The set of functions which we are now going to discuss come under the category of buffered file system. This file system is referred to as buffered because, the routines maintain all the disk buffers required for reading / writing automatically.</p>
<p>To access any file, we need to declare a pointer to FILE structure and then associate it with the particular file. This pointer is referred as a file pointer and it is declared as follows:</p>
<p><em><strong>FILE *fp;</strong></em></p>
<p><a title="Open A File Using The Function fopen( )" href="http://clinuxpro.com/fopen">Open A File Using The Function fopen( )</a><br />
<a title="Close A File Using The Function fclose( )" href="http://clinuxpro.com/fclose">Close A File Using The Function fclose( )</a></p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/file-pointer/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Files In C</title>
		<link>http://clinuxpro.com/files-in-c</link>
		<comments>http://clinuxpro.com/files-in-c#comments</comments>
		<pubDate>Wed, 25 Apr 2012 14:19:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming]]></category>
		<category><![CDATA[File Handling in C]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1582</guid>
		<description><![CDATA[Files In C discusses methods of working with files, and a data structure to store data. C views file simply as a sequential stream of bytes.]]></description>
			<content:encoded><![CDATA[<p>When data is stored using variables, the data is lost when the program exits unless something is done to save it. This tutorial discusses methods of working with files, and a data structure to store data. C views file simply as a sequential stream of bytes.</p>
<p>Each file ends either with an end-of-file marker or at a specified byte number recorded in a system maintained, administrative data structure. C supports two types of files called binary files and text files.</p>
<p>The difference between these two files is in terms of storage. In text files, everything is stored in terms of text i.e. even if we store an integer 54; it will be stored as a 3-byte string &#8211; “54\0”. In a text file certain character translations may occur. For example a newline(\n) character may be converted to a carriage return, linefeed pair. This is what Turbo C does. Therefore, there may not be one to one relationship between the characters that are read or written and those in the external device. A binary file contains data that was written in the same format used to store internally in main memory. For example, the integer value 1245 will be stored in 2 bytes depending on the machine while it will require 5 bytes in a text file. The fact that a numeric value is in a standard length makes binary files easier to handle. No special string to numeric conversions is necessary.</p>
<p>The disk I/O in C is accomplished through the use of library functions. The ANSI standard, which is followed by TURBO C, defines one complete set of I/O functions.But since originally C was written for the UNIX operating system, UNIX standard defines a second system of routines that handles I/O operations. The first method,defined by both standards, is called a buffered file system. The second is the unbuffered file system.</p>
<p>In these tutorials, we will first discuss buffered file functions and then the unbuffered file functions.</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/files-in-c/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

