Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
4Activity
0 of .
Results for:
No results containing your search query
P. 1
Data Structures

Data Structures

Ratings: (0)|Views: 49 |Likes:
Published by karthikeg01

More info:

Published by: karthikeg01 on May 18, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as RTF, PDF, TXT or read online from Scribd
See more
See less

06/28/2013

pdf

text

original

 
1. FILES
Large amount of data/ info has to be written to or from anauxiliary storage device. Such information is stored on thedevice in the form of a data file.There are two different categories of data files.- Stream oriented data files- System oriented data files.Stream oriented data files are of two types.Text files individual data items or component ostrings or numbers. (Formatted data files)Binary files Unformatted data files, organizes data into blocks containing contiguous bytes oinformation.System oriented data files are more closely related to thecomputer’s Operating System than the stream-oriented datafiles.To perform the Input/Output from and to files, an extensiveset of library functions are available in C.Access to files generally requires four basic operations.Open -This allows access to a file and establishesthe position, or offset, in the file.Close-This ends access to the file, When access toa file is complete, it should be closed. Thenumber of files that a running program canhave at any time is limited; by closing files properly these limited facilities can be used
 
more intelligently.Read- This gets information from the file, either inthe form of character strings, or in the formof data (combined integers, characters,floating point numbers, & structures.)Write-This adds information to the file or replacesinformation already on the file.
1.1 Opening & Closing of a data file
When working with a stream-oriented data file, the firststep is to establish a buffer area, where information istemporarily stored while being transferred between thecomputer’s memory and the data file. The buffer area isestablished by writingFILE *ptvar;where FILE is a special structure type that establishes the buffer area, & ptvar is a pointer variable that indicates the beginning of the buffer area. The structure type FILE isdefined within a system include file stdio.h
Opening a file : fopen()
The standard I/O function used to open a file is namedfopen(). This associates the file name with the buffer area. It returns a pointer to the structure FILE. The returnvalue must be saved because all ther functions for filehandling requires this as an argument.
Function name:
(FILE *) fopen(file_name, mode)
Description
 
This function opens a file and establishes a current offsetwithin the file. This must be done before attempts aremade to read from or write to the file.
Argument list
(char *) file_name The starting address of a character string describing the name of the file.This can be either a character string, or array name, or a character pointer.(char *) mode-This describes the actions to be performed on the file and governs theinitial offset in the file. The modes for opening a file are:r -Opened for reading. Positioned at the beginning of the file.w - Opened for writing. The assumption isthat the file is to be created. If the filedoes not exist, it is created, if it doesexist, it is truncated. Positioned at the beginning of the file.a -Opened for writing. Same rules applyas for mode w except that initial positioning is at the end of the file andthe file is not truncated.r+ - Opened for update. File is available for reading and writing but is nottruncated. The initial positioning is atthe start of the file.w+ -Opened for update. File is available for reading & writing and is truncated if 

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->