home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
MBUG
/
MBUG063.ARC
/
CHAP1.TXT
< prev
next >
Wrap
Text File
|
1979-12-31
|
8KB
|
191 lines
Chapter 1 - Getting Started
WHAT IS AN IDENTIFIER?
Before you can do anything in any language, you must at
least know how you name an identifier. An identifier is
used for any variable, function, data definition, etc. In
the programming language C, an identifier is a combination
of alphanumeric characters, the first being a letter of the
alphabet or an underline, and the remaining being any letter
of the alphabet, any numeric digit, or the underline. Two
rules must be kept in mind when naming identifiers.
1. The case of alphabetic characters is significant.
Using "INDEX" for a variable is not the same as using
"index" and neither of them is the same as using
"InDeX" for a variable. All three refer to different
variables.
2. As C is defined, up to eight significant characters can
be used and will be considered significant. If more
than eight are used, they may be ignored by the
compiler. This may or may not be true of your
compiler. You should check your reference manual to
find out how many characters are significant for your
compiler.
It should be pointed out that some C compilers allow
use of a dollar sign in an identifier name, but since it is
not universal, it will not be used anywhere in this
tutorial. Check your documentation to see if it is
permissible for your particular compiler.
WHAT ABOUT THE UNDERLINE?
Even though the underline can be used as part of a
variable name, it seems to be used very little by
experienced C programmers. It adds greatly to the
readability of a program to use descriptive names for
variables and it would be to your advantage to do so.
Pascal programmers tend to use long descriptive names, but
most C programmers tend to use short cryptic names. Most of
the example programs in this tutorial use very short names
for that reason.
Any computer program has two entities to consider, the
data, and the program. They are highly dependent on one
another and careful planning of both will lead to a well
planned and well written program. Unfortunately, it is not
possible to study either completely without a good working
knowledge of the other. For this reason, this tutorial will
jump back and forth between teaching methods of program
writing and methods of data definition. Simply follow
Page 4
Chapter 1 - Getting Started
along and you will have a good understanding of both. Keep
in mind that, even though it seems expedient to sometimes
jump right into the program coding, time spent planning the
data structures will be well spent and the final program
will reflect the original planning.
HOW THIS TUTORIAL IS WRITTEN
As you go through the example programs, you will find
that every program is complete. There are no program
fragments that could be confusing. This allows you to see
every requirement that is needed to use any of the features
of C as they are presented. Some tutorials I have seen give
very few, and very complex examples. They really serve more
to confuse the student. This tutorial is the complete
opposite because it strives to cover each new aspect of
programming in as simple a context as possible. This
method, however, leads to a lack of knowledge in how the
various parts are combined. For that reason, the last
chapter is devoted entirely to using the features taught in
the earlier chapters. It will illustrate how to put the
various features together to create a usable program. They
are given for your study, and are not completely explained.
Enough details of their operation are given to allow you to
understand how they work after you have completed all of the
previous lessons.
A DISCUSSION OF SOME OF THE FILES
CCL.BAT
This file, which does not exist on the distribution
disk, is the batch file that calls in an editor, then the
compiler (Pass 1 and Pass 2, if it exists), and finally runs
the resulting compiled program. There are several examples
of batch files which can be used with various compilers
given in the "COMPILER.DOC" file on the distribution
diskette. It is up to you to type in a batch file for use
with your particular compiler, considering also the method
required to call in your editor. To use it, simply type the
batchfile name with the desired filename. After typing in
your particular CCL.BAT file, try it by typing CCL FIRSTEX.
You will get the source file displayed on the monitor by
your editor. If you don't have one of the compilers listed
in the "COMPILER.DOC" file, you will have to modify the
batch file for your particular compiler.
The pass or passes of the compiler will be executed,
followed by the linking process. The final program will be
loaded and run, then the files generated by the process will
be erased to prevent filling the disk up.
Page 5
Chapter 1 - Getting Started
If you have a hard disk available, it will be up to you
to modify the batch file to perform the above described
operations.
Even though you will have a lot of files to compile and
run, you will find that a batch file similar to this will do
most of the work for you and you will proceed very quickly.
In order to do the programming exercises, you will need
to go through the same steps as when running the example
programs. This is simple to do by simply typing your own
filename with the CCL program call. It is highly
recommended that you do the programming exercises to gain
the programming experience.
LIST.EXE
This file will list the source files for you with line
numbers and filename. To use it, simply type "LIST"
followed by the appropriate filename. Type LIST FIRSTEX.C
now for an example. The C source code is given later in
Chapter 14 along with a brief description of its operation.
PRINTALL.BAT
This is a batch file that will call the above LIST.EXE
file once for each of the example C programs, printing all
of the files out. If you want a hardcopy of all of the
files, enter PRINTALL and watch as your printer fills about
150 sheets of paper with C programs.
Page 6