Professional Documents
Culture Documents
Presentation On Data File Handling
Presentation On Data File Handling
DATA FILE
HANDLING
Presented by :--
Naveen Verma
INTRODUCTION
File Handling is made up of two
different words…….
storing information
permanently.
For eg– Word processor
INPUT STREAM
Read data from Disk INPUT DATA
Disk Program
OUTPUT STREAM
File
OUTPUT DATA
Write data to Disk
File Input and Output using Streams
ios
iostream
fstreambase
DATA FILES
Writing to a file
file.
Closing a file.
OPENING OF FILES
For opening you must first choose
the stream .
There are 3 streams.
(ifstream,ofstream,fstream)
Opening of file is of 2 ways :---
1) Using constructor function.
DATA
FILE Nav
Program
When we use a file pointer to traverse
the file then we use function --
fopen( )
Syntax ::--::>
fopen(“File name”,”file mode”);
Example
FILE *fp;
fp=fopen(“Naveen.Txt”,”r”);
fopen( ) performes 3 main functions :-
SEEK_END==means move
pointer from end of the file.
SEEK_CUR==means move pointer
with reference to its current
position.
SEEK_SET==means move pointer
with reference to the beginning of
file.
Ftell()==tells u the current position
of pointer.
i.e-- position=ftell(fp);
Program to dislpay
characters of your text
file in any directory to
console……..
#include <stdio.h>
void main()
{
FILE *fopen(), *fp;
int c ;
fclose( fp );
getch();
}
Program to get record
from keyboard and then
write them on the file in
binary mode.
#include "stdio.h"
Void main( )
{
FILE *fp ;
char another = 'Y' ;
struct emp
{
char name[40] ;
int age ;
float bs ;
};
struct emp e ;
fp = fopen ( "EMP.DAT", "wb" ) ;
if ( fp == NULL )
{
puts ( "Cannot open file" ) ;
exit( ) ;
}
while ( another == 'Y' )
{
printf ( "\nEnter name, age and basic salary: " ) ;
scanf ( "%s %d %f", e.name, &e.age, &e.bs ) ;
fwrite ( &e, sizeof ( e ), 1, fp ) ;
printf ( "Add another record (Y/N) " ) ;
fflush ( stdin ) ;
another = getche( ) ;
}
fclose ( fp ) ;
}
THANK YOU VERY
MUCH
&
SORRY FOR MY
FAULTS
By :--
N@VEEN VERMA