Share this:


UNIT – 10

FILE MANAGEMENT
What is a File?
Abstractly, a file is a collection of bytes stored on a secondary storage device, which is generally a disk of some kind. The collection of bytes may be interpreted, for example, as characters, words, lines, paragraphs and pages from a textual document; fields and records belonging to a database; or pixels from a graphical image. The meaning attached to a particular file is determined entirely by the data structures and operations used by a program to process the file. It is conceivable (and it sometimes happens) that a graphics file will be read and displayed by a program designed to process textual data. The result is that no meaningful output occurs (probably) and this is to be expected. A file is simply a machine decipherable storage media where programs and data are stored for machine usage.

ASCII Text files

Binary files

Creating a file and output some data

The file name is any valid DOS file name, and can be expressed in upper or lower case letters, or even mixed if you so desire. It is enclosed in double quotes. For this example we have chosen the name TENLINES.TXT. This file should not exist on your disk at this time. If you have a file with this name, you should change its name or move it because when we execute this program, its contents will be erased. If you don’t have a file by this name, that is good because we will create one and put some data into it. You are permitted to include a directory with the file name. The directory must, of course, be a valid directory otherwise an error will occur. Also, because of the way C handles literal strings, the directory separation character ‘’ must be written twice. For example, if the file is to be stored in the PROJECTS sub directory then the file name should be entered as “\PROJECTS\TENLINES.TXT”. The second parameter is the file attribute and can be any of three letters, r, w, or a, and must be lower case.

Reading (r)

Writing (w)

Appending (a):

When a file is opened for appending, it will be created if it does not already exist and it will be initially empty. If it does exist, the data input point will be positioned at the end of the present data so that any new data will be added to any data that already exists in the file. Using the a indicates that the file is assumed to be a text file.

Outputting to the file

Closing a file

In this program we check to see that the file exists, and if it does, we execute the main body of the program. If it doesn’t, we print a message and quit. If the file does not exist, the system will set the pointer equal to NULL which we can test. The main body of the program is one do while loop in which a single character is read from the file and output to the monitor until an EOF (end of file) is detected from the input file. The file is then closed and the program is terminated. At this point, we have the potential for one of the most common and most perplexing problems of programming in C. The variable returned from the getc function is a character, so we can use a char variable for this purpose. There is a problem that could develop here if we happened to use an unsigned char however, because C usually returns a minus one for an EOF – which an unsigned char type variable is not
capable of containing. An unsigned char type variable can only have the values of zero to 255, so it will return a 255 for a minus one in C. This is a very frustrating problem to try to find. The program can never find the EOF and will therefore never terminate the loop. This is easy to prevent: always have a char or int type variable for use in returning an EOF. There is another problem with this program but we will worry about it when we get to the next program and solve it with the one
following that.

Overview

Include Syntax

Object-like Macros
An object-like macro is a simple identifier which will be replaced by a code fragment. It is called object-like because it looks like a data object in code that uses it. They are most commonly used to give symbolic names to numeric constants.

Conditional Syntax

Ifdef

If

Defined

Else

Elif


SYSTEM DEVELOPMENT

EcoleBooks | COMPUTER As LEVEL(FORM FIVE) NOTES - FILE MANAGEMENT
EcoleBooks | COMPUTER As LEVEL(FORM FIVE) NOTES - FILE MANAGEMENT
EcoleBooks | COMPUTER As LEVEL(FORM FIVE) NOTES - FILE MANAGEMENT
EcoleBooks | COMPUTER As LEVEL(FORM FIVE) NOTES - FILE MANAGEMENT
EcoleBooks | COMPUTER As LEVEL(FORM FIVE) NOTES - FILE MANAGEMENT

Programming Paradigm

Software Design Paradigm

Design Patterns:

Components:

Software Architecture:

Frameworks:

Build and Fix model

EcoleBooks | COMPUTER As LEVEL(FORM FIVE) NOTES - FILE MANAGEMENT

Waterfall and Modified Waterfall models

Waterfall Model

Offered a means of making the development process more structured, expresses the interaction between subsequent phases.

EcoleBooks | COMPUTER As LEVEL(FORM FIVE) NOTES - FILE MANAGEMENT

Modified Waterfall Model

EcoleBooks | COMPUTER As LEVEL(FORM FIVE) NOTES - FILE MANAGEMENT

Rapid Prototyping

EcoleBooks | COMPUTER As LEVEL(FORM FIVE) NOTES - FILE MANAGEMENT

Boehm’s Spiral Model

Variables and Types

Functions (Procedures)

EcoleBooks | COMPUTER As LEVEL(FORM FIVE) NOTES - FILE MANAGEMENT
EcoleBooks | COMPUTER As LEVEL(FORM FIVE) NOTES - FILE MANAGEMENT

Data Exchange between Functions (Procedures)

Passing arguments to a function

Polymorhic Languages

Variable Scope

Software Design Methodology (Procedural Paradigm)

Design

Implementation

Testing


EcoleBooks | COMPUTER As LEVEL(FORM FIVE) NOTES - FILE MANAGEMENT

subscriber

1 Comment

  • EcoleBooks | COMPUTER As LEVEL(FORM FIVE) NOTES - FILE MANAGEMENT

    Namutosi Hellen Torofain, January 4, 2024 @ 5:44 pm Reply

    Excellent

Leave a Reply

Your email address will not be published. Required fields are marked *

Accept Our Privacy Terms.*