![Up](_derived/up_cmp_sumi-painting-smallfont110_gbtn.gif)
C Programming
Structures, Enumerations,
and File Processing
This page will contain information about
Structures, Enumerations, and File Processing with the C language.
There
are many more subjects that could be covered, but due to lack of time and
space they are not included in this web site.
![](_themes/sumi-painting-smallfont/sumhorsa.gif)
STRUCTURES
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
Structures are collections
of related variables, sometimes referred to as aggregates, under one name. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
Structures can contain variables
of different data types. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
The keyword struct begins
every structure definition. Within the braces of the structure definition
are the structure member declarations. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
Members of the same structure
must have unique names. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
A structure definition creates
a new data type that can be used to declare variables. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
There are two methods for declaring
structure variables. The first method is to declare the variables in a
declaration as is done with variables of other data types using struct
tagName as the type. The second method is to include the variables
between the closing brace of the structure definition and the semi-colon
that ends the structure definition. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
The tag name of the structure
is optional. If the structure is defined without a tag name, the variables
of the derived data type must be declared in the structure definition,
and no other variables of the new structure type can be declared. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
A structure can be initialized
with an initializer list by following the variable name in the structure
declaration with an equal sign and a comma-separated list of initializers
enclosed in braces. If there are fewer initializers in the list than members
in the structure the remaining members are automatically initialized to
zero (or null
if the member is a pointer). |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
Entire structures may be assigned
to structure variables of the same type. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
A structure variable may be
initialized with a structure variable of the same type. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
The structure member operator
( . ) --also called the dot operator-- is used when accessing
a member of a structure via the structure variable name. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
The structure pointer operator
(
->
)-- also called the arrow operator -- is used when accessing a member
of a structure via a pointer to the structure. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
Structures and individual members
of structures are passed to functions call by value. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
To pass a structure call
by reference, pass the address of the structure variable. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
An array of structures is automatically
passed call by reference. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
To pass an array call by value,
create a structure with the array as a member. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
Creating a new name with typedef
does
not create a new type; it creates a name that is synonymous with a previously
defined type. |
Enumerations
An enumeration.designated
by the keyword enum, is
a set of integers that are represented by identifiers. The values in an
enum
start with 0 unless specified otherwise, and are always incremented
by 1.
An example of a statement
of this type follows:
enum months
(JAN = 1, FEB, MAR, APR, MAY, JUN);
FILE
PROCESSING
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
All data items processed
by a computer are reduced to combinations of zeros and ones. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
The smallest data item
in a computer (a bit) can assume the value 0 or the value 1. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
Digits, letters, and
special symbols are referred to as characters. Together they are called
the computer's character set. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
A field is a group of
characters that conveys meaning. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
A record is a group
of related fields. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
At least one field in
each record is normally chosen as a record key. The record key identifies
a record as belonging to a particular person or entity. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
One type of organization
for records in a file is called a sequential access file in which records
are accessed consecutively until the desired data are located. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
A group of related files
is sometimes called a database. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
A collection of programs
designed to create and manage databases is called a database management
system (DBMS). |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
C views each file simply
as a sequential stream of bytes. |
![](_themes/sumi-painting-smallfont/sumbul1a.gif) |
C automatically opens
3 files and their associated streams--standard input, standard output,
and standard error--when program execution begins. |
|