100% found this document useful (1 vote)
610 views630 pages

Using QuickC PDF

Uploaded by

julio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
610 views630 pages

Using QuickC PDF

Uploaded by

julio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 630

#

Werner
Feibel

L
i
Using QuickC
®
Using QuickC

Werner Feibel

Osborne McGraw-Hill
Berkeley, California
Osborne McGraw-Hill
2600 Tenth Street
Berkeley, California 94710
U.S.A.

For information on translations and book distributors outside of the U.S.A., write to
Osborne McGraw-Hill at the above address.
A complete list of trademarks appears on page 595.

Using QuickC®
Copyright © 1988 by McGraw-Hill, Inc. All rights reserved. Printed in the United States of
America. Except as permitted under the Copyright Act of 1976, no part of this publication

may be reproduced or distributed in any form or by any means, or stored in a database or


retrieval system, without the prior written permission of the publisher, with the exception
that the program listings may be entered, stored, and executed in a computer system, but
they may not be reproduced for publication.

1234567890 DODO 8987


ISBN 0-07-881292-5

information has been obtained by Osborne McGr«w-Hill from sources believed to be reliable. However,
because of the possibility of human or mechanical error by our sources. Osborne McGraw-Hill, or others, Osborne
IVIcCraw-Hill does not guarantee the accuracy, adequacy, or completeness of any information and is not responsible
for any errors or omissions or the results obtained from use of such information.
For my parents, with love and thanks
for all they've done for me

J
Contents
Introduction xiii

Introducing C 1
C Features 2
An Example of C Programming 3
The Nature of C 5
Using C 7
Why QuickC U

A Quick Lool( at Quicl( C 13


Hands-on QuickC 14
Exploring Program Execution 28
QuickC Commands 3g
Summary 72

Simple Types and Operators 73


C Program Structure 74
Statements 80
Identifiers
g]
Variable Definition: Making Room 84
Simple Data Types 88
Variants on Simple Type 99
Constants lOi
Arithmetic Operators 107
printO Once More II3
Summary II4

Preprocessors and Programs 115


Program Structure 115
The C Preprocessor 119
)

Preprocessor Commands 122


Library Functions 135
Macros That Look Like Functions 141
Header and Other Inrlude Files 143
Summary 144

5 Reading and Writing in C 145


Reading Characters 146
More About printf( 153
Values and Variables: The Address Operator 158
Summary 165

6 Controlling C 167
Relational and Equality Operators 168
Logical Operators 170
The if-else Construct 172
The switch Statement 178
More Operators 182
Loops in C 186
Components of the while Loop 188
The do-while Loop 191
The for Loop 193
break and continue 201
Summary 204

7 Functioning in C 205
C Functions 206
Flow of Control 207
Function Returns 213
Formal and Actual Parameters 217
Summary 225

8 Function Prototypes 227


Influence of Prototypes on Syntax for Formal Parameters 231
Syntax: Old and New 237
Functions: Miscellaneous Points 237
Summary 238

9 Scope, Lifetime, and Storage Class 239


Scope and Visibility 239
Duration of Variables 249
Storage Class 251
Default Storage Classes and Storage Durations 259
Summary 261
)

10 Pointers 263
Objects, Lvalues, Values 264
Pointers 267
Pointers as Function Parameters 274
Pointer Arithmetic 280
Miscellaneous Points 284
Pointer Pitfalls 285
Summary 287

I 11 Arrays and Strings 289


Array Basics 290
Arrays and Pointers 293
Array Parameters 298
Strings 303
Multidimensional Arrays 315
Pointer Arrays 322
Summary 327

12 l\/lore on Functions and IVIore Functions 329


Functions Returning Pointers 330
Error Handling and stderr 338
Adding to Your Function Collection 344
Recursion 359
Summary 368

13 Command Line Arguments 369


main( ) as Program and as Function 370
What Are Command Line Arguments? 371
Command Line Arguments in DOS 372
Arguments to main( 376
A Program to Exercise Command Line Arguments 382
Summary 390

14 Fiies and l\/lemory 391


Files 392
Dynamic Memory Allocation 403
Summary 420

15 Bit and Other Operators 421


Bitwise Operators 421
The Conditional Operator 451
Summary 455
16 Structures, Unions, and Other Types 457
Structures 458
Bit-Fields 492
Unions 497
Enumeration Types 500
Summary 502

17 QuickC Library Functions 505


stdio.h 506
stdlib.h 515
string.h 525
ctype.h 536
dos.h 541
io.h 548
math.h 551
Other Files 555
Summary 556

A ASCII Codes 557

B Building Libraries in Quicl(C 559


Building Quick Libraries 560
Building Stand-Alone Libraries 564
Summary 569

C QuickC Command Summary 571


Commands for Calling QuickC 572
Useful Commands in the QuickC Environment 573
Editing Commands 573
Menu Commands 576
Compiling and Linking Outside of QuickC 584
Controlling the Linker 586

D Features of QuickC and IVIicrosoft C 5.0 589


Environment and Performance 589
Memory Models and Libraries 590
Debugging 592
Miscellaneous 593
Similarities 593

Index 597
Acknowledgments

Many people deserve thanks for making this book possible. The following
people were particularly helpful and encouraging throughout the project.
Kris Jamsa deserves thanks for his technical review and very helpful
suggestions. Many of the book's good features are there because of his
suggestions and corrections; the book's defects are there because I didn't listen
to Kris's objections.
I also wish to thank the people at Osborne/ McGraw-Hill who are always
helpful, friendly, and accommodating; it has been a pleasure to work with
them. Jeff Pepper deserves special thanks for getting this project started and
for keeping it on the smoothest course and Lyn Cordell
possible. Liz Fisher
helped keep me on course, and dealt gracefully and efficiently with ambiguous
materials and last minute changes, for which I thank them. Thanks also to the
unsung heroes in the art and production departments at Osborne/ McGraw-
Hill. They had to work extra hard (on a tight schedule made even tighter by
changes required late in the production process) to turn the manuscript into a
real book.
owe my friends many thanks for putting up with me and keeping
Finally, I

me going during the past few months. In particular, I want to thank Luanne
Panarotti, Scott Barnes, Alexa Beiser, Dan Kiely, and little Dylan Reiser
Kiely, whose favorite part of the project was the printer cable.
This book may have gotten done without these people, but it would have
been a lot less fun.
Introduction

Welcome to C and QuickC environment! You can use this book to


to the learn
about both the C language and the QuickC implementation.
C is a small but extremely powerful language that becoming the
is

language of choice for all sorts of software development Programs


projects.
written in C range from simple utilities through data base management
systems to compilers (including C compilers!) and operating systems. QuickC
is an interactive, easy-to-use, programming environment that provides all the

necessary components to create, compile, test, and run C programs.


QuickC is an ideal environment for learning C because it enables your
editor, compiler, and debugger to support each other. This makes the program
development process much faster and more convenient. For example, the
QuickC compiler can keep a record of the errors it finds while compiling your
program and put you back in the editor at the location of the first error when
the compiling is done. The QuickC editor lets you jump from one compiler
error to the next, and make all your corrections in one session. Then, with a
single keystroke, you can compile and run your program again. If you're
familiar with other compilers that require you to make corrections one at a
time (leaving the compiler and starting the editor as a separate program each
time), you will appreciate this feature. If you haven't worked with compilers
before, you'll learnfrom the start how convenient programming in C can be.
This book introduces you to the C programming language and shows you
how to use Quick C to write programs quickly and effectively. My purpose has
been to explain the advantages of C and the features of the QuickC program-

xlll
xiv Using QuickC

ming environment. In later chapters, youll find sections that illustrate how to
use various QuickC features as part of the discussion of particular C con-
structs. I've also included advice on some pitfalls you may encounter when

writing C programs and on how to avoid them.


The book focuses on the version of C implemented in QuickC and in the
Microsoft C version 5.0 compiler. This version of C conforms to the official

language definition currently being drafted, so you can also use this book to
learn C with other compilers.
The text contains lots of examples, since these usually illustrate a point
better than several paragraphs of description. Youll also find suggested modi-
ficationsand variations to try. The programs are designed to let you experi-
ment easily, and many of them will report on their own actions.
The best way to learn a programming language is to use it. Whether your
main interest is in C or QuickC, you'll get a lot more out of this book and —
enjoy it much more — if you enter the programs and examples and try them
out yourself Once you've done that, experiment with the examples; change
some of the functions or the input. One of the best ways to deepen your
understanding of a language is to experiment with it. Then, once you feel

comfortable with the material covered here, work on projects that interest you.
You'll find it is helpful, though not essential, to have some familiarity with
programming — perhaps with a language such as Pascal or BASIC. If you
have used either or both of these languages, you'll find that C differs in
important, and sometimes in very subtle, ways. If you have no programming
experience, don't worry. You'll still be able to use this book, but you may need
to put in some extra effort to be sure you understand some of the terms and
concepts.

Program Source Files

This book contains dozens of programs that illustrate C concepts. Many of


these programs are designed and exploration, and some
for experimentation
are quite entertaining to use, such as the trivial-fact generating programs in
Chapter 2. Throughout the book, I encourage you to play with the
programs —
to enter, compile, and run them —
and to observe the effects when
you modify them.
Introduction

The complete source code for all the programs is included here, so you can
simply type them in from the book. However, if you want to save yourself the
demands of that task, the source code for all the programs in this book (as well
as some additional programs and functions) can be purchased on two 360K
diskettes, for $22 ($20 plus $2 for postage and handling). The diskettes contain
about 450K of source files. In addition to the programs from the book, these
files include a quick and dirty program for testing functions during develop-

ment, a simple daily reminder program that you can tailor to your needs, and
several others.
To order the diskette, use the form that follows this introduction.
To order the source code diskettes for Using QuickC, please provide the
following information and a check or money order for the appropriate
amount:

$25 per copy ($20 + $5 shipping and handling) for foreign orders
$23 per copy ($20 + $2 shipping and handling + $ sales tax) for Massachu-
1

setts residents

$22 per copy ($20 + $2 shipping and handling) for other orders

Number of copies: Amount enclosed:

Name

Company (if applicable).

Street Address

City State ZIP Code.

Please send this information, along with your check or money order to:

Werner Feibel
P.O. Box 2499
Cambridge, MA 02238
Osborne/ McGraw-Hill assumes no responsibility for this offer. This is solely
the offer of Werner Feibel, and not of Osborne/ McGraw-Hill.
I

A
1
Introducing C

C is an elegantly simple language; it is also a challenge to programmers. At


times, you will love C; at other times, you'll hate it.

There is much to like about C: it is small, powerful, and when used


properly, C is fast, efficient and portable, meaning that it's moved easily from
one computer or operating system to another.
C lets you do marvelous things, such as building compilers, operating
systems, and editors. C can also turn nasty — overwriting compilers, operating
systems, editors, or whatever else you may have stored in your system's
memory.
C you the power and potential portability of high-level languages
gives
such as Pascal or Modula-2 along with the flexibility and destructive potential
of low-level languages, such as assembly language. C lets you build complex
data structures found in other high-level languages and enables you to manipu-
late individual bits of that data structure in ways normally possible only with
assembly language.
However, C will not protect your programs from themselves, and will let

them destroy your data if you are not careful.


Using QuickC

On balance, you'll be able to do all sorts of things with C, without getting


yourself into any more trouble than with another programming language — as
long as you don't get too fancy or too sloppy.
Every language — whether English or C — has a set of rules that defines
the language. For example, in English, a period ends a sentence. Such a set of
rules known as a syntax for the language. Learning the syntax is the easy part
is

of C; learning how to use the language to its fullest is your real challenge. Your
rewards, which include programming power and a better understanding of
your computer, are definitely worth the effort.
Microsoft Corporation's QuickC makes C
and accessible by
available
providing a complete, easy-to-use language implementation. QuickC is an
enhanced compiler (it converts programs into object code), a linker (it pro-
duces executable files), a shell (it serves as a command interpreter), and a rich
programming environment. With the help of this book, you'll be able to take
advantage of QuickC's special features, and make C work for you.

C Features

Several features make C a very attractive programming language for projects


large and small. These include performance features, such as speed and
efficiency of your executable program, and also features relating to the trans-
portability and modularity of programs. Modularity lets you break a large
program into small, manageable pieces, which you may be able to reuse in
other programs. Of course, the extent to which a particular program takes
advantage of these features of C depends on how well the program is written.
The examples in this text provide a solid foundation for you to develop good C
programs.

Performance Features
C is smaller than Pascal, Modula-2, or even BASIC. C has only about 30
keywords or reserved words. Because many of C's actions are close to
assembly-level activity, using C can increase the speed of your program and
make it easier to create concise, "optimized" expressions.
Introducing C

C gives you a complete set of tools. It's your job to maximize its potential.
Because C lets you get very close to the actual memory cells and registers in
your computer, you can do just about anything in a C program. This capability
makes C very powerful — ideal for complex projects, or programs that need to
take full advantage of the system on which they are running.

Portability

C can be very portable. One reason for C's portability is the preprocessor,
which makes it possible to substitute information specific to a particular
machine when compiling or running a program. As you'll see in later chapters,

you can use the preprocessor to help make your programs run faster.

IVIodularity

One feature that helps make C portable is its capacity to build programs out of
small functions and library modules that have already been compiled. The
library modules can contain C functions specific to a particular machine.
Because you can build and compile independent function libraries. C allows
you to write programs in a modular fashion. You can break large programs
into smaller units, which contain functions that can be used together in other

applications. Because individual modules are built and modified separately,


you can use a strategy that makes it easier to move programs to other
machines.

An Example of C Programming
The following listing shows one way of incorporating information from other
files into a program, and illustrates one way of increasing program portability.

/• Progreun showing the use of an Include file containing program specific


messages. Each program can have Its own system or program
specific include file.
•/
:

Using QuickC

#include "proginfo.h" /* a file containing various definitions. */

main C) /* the main C program */


<
/* write value of PROG_MESSAGE to screen */
printl ( "•/.s\n", PROG.MESSAGE)
}

The main program, the C function niain( ), simply writes something to


the screen: the value of something named PROG_MESSAGE.
The writing is done by the function printf( ), which is predefined for you in
QuickC and other C implementations. The function printf( ) writes whatever
you tell it to. In this case, the program tells it to write the value of
PROG_MESSAGE.
When it encounters the\n, printf( ) writes a carriage return and a line

feed, which puts the cursor at the leftmost column of the next line.
The % begins a placeholder for a particular type of information, whose
value is substituted when printf( ) writes the material; the s indicates that a
string is to be written. In our example, %s is the placeholder for PROG
MESSAGE, which contains a string. In C, a string is a sequence of characters
terminated by a special character, which we'll discuss later.

The escape code \n compact way of moving the cursor in a particular


is a
way. Later, we'll study the syntax for printf( ) in more detail, including how to
write other types of information (such as integers and real numbers), and there
will be more about escape codes, such as \n.

The structure of function main( ) illustrates the format of functions in C.


A function starts with a name (in this case, main), followed by parentheses
(which may have something between them). The main body of a function is

enclosed in braces.

Within the body of the function, individual statements end with a semi-
colon. Comments may appear anywhere in a program, and are enclosed
between /* and */.
Note that PROG MESSAGE is not defined anywhere in the program
file. Rather, this value is specified in the header file, proginfo.h, which the
compiler reads when processing the file containing the main program. Such
header files are common
Each system or program may have its own
in C.

header files. These files contain program or operating system specific values
and definitions. For example, when running under QuickC, the program's
Introducing C

message would read "QuickC Version 1.0"; running under Microsoft C Ver-
sion 5.0, the message might be "Microsoft C Version 5.0. "These messages are
stored in a file such as proginfo.h.
Most C compilers provide a file called stdio.h. which contains system-and
implementation-specific information, and which associates specific values,
such as "QuickC Version 1.0" with names, such as PROG MESSAGE.
Search your QuickC directories for files with the extension .h. These are the
header files provided with your compiler.

The Nature of C
C can be described as a middle-level language, having characteristics and
capabilities of both high- and low-level languages. This is one reason for its

apparently contradictory properties. C lets you create complex data struc-


tures, as do other high-level languages. However, unlike such languages, C
does minimal range and type checking when you use such variables. At the
other extreme, C lets you look at the contents of specific address locations in
memory; C even lets you do arithmetic with addresses. Such capabilities are
available in assembly languages, but rarely in high-level languages.
There are several reasons for C's contrasting features. It was designed to
be and portable. Dennis Ritchie, who developed C,
flexible, permissive, fast,

and Brian Kernighan, who was involved in much of the early work with C,
intended C to be useful for writing systems (such as operating systems) as well
as application programs (such as editors). Therefore, the developers gave C the
speed and flexibility of assembly language, but the data structures and control
constructs (such as if-then, for, while) of high-level languages.
Table 1-1 lists some properties of high- and low-level languages, and
indicates where C stands with respect to these properties. Note that C has
almost every property listed.

A Small Language
C has a very small vocabulary — only about 30 keywords. Although the words
are few, you can say a great deal with them. A small vocabulary does not mean
Using QuickC

Table 1-1. C Measured Against the Properties of High- and Low-level


Languages

High-level Languages C Low-level Languages

Structured yes yes Fast


Easy to use yes yes Compact
Safeguards yes/no yes (Can be) efficient
Complex data structures yes yes Address and bit manipulation

a weak language: some linguists claim that fewer than 900 words are needed
to communicate effectively in English.
On the other hand, C has lots of operators or symbols that cause specific
actions. In fact, C has more operators than keywords! This combination of a
small vocabulary and many operators lets you use C as a "construction set."
You can easily create individual statements or functions to do just the right
amount of work. As you'll see, C programs are usually built of small functions
that perform specific tasks. These functions are collected in modules and used
as needed.

The Power of C
Despite its smallC is being used for a huge range of programs. Large parts
size,

of the powerful UNIX and DOS operating systems are written in C. Similarly,
C has been used to write compilers (including C compilers), editors, typeset-
tingprograms (such as troff and TeX), and such programs as dBaselll and
Microsoft Windows.
At the other end of the spectrum, you will find many C programs that
perform specific tasks, such as display a calendar for any month or year, count
thenumber of words in a file, list the contents of a directory, find a particular
word or other expression in specified files, compute the interest payments on a
loan under various conditions, and so on. Source code for many of these
Introducing C

programs on electronic bulletin boards, from user groups, or in


is available
inexpensive utility packages. You may want to look at (or use) some of these
programs, to study and play with the code. In later chapters we'll look at a few
programs of this sort.

Standard Versions
There is as yet no official standard for C. Although C is used everywhere, it is

only now being officially defined. There has been a de facto standard version
of the language, summarized in The C Programming Language by Brian
Kernighan and Dennis Ritchie (Englewood Cliffs, New Jersey:
Prentice-Hall, 1978). This version of C is known as "K&R C," with compilers
often claiming that they implement "full K&R C," or "K&R C, with exten-
sions."
After several years, however, a standards committee is about to complete
its work on an official definition of the language. The working name for this
version is "Draft Proposed ANSI Standard C." Eventually, C's official name
will be "ANSI Standard C." (ANSI stands for American National Standards
Institute.)

The committee's task is to resolve ambiguities and to make it easier to


port C programs. Also, without sacrificing any of C's power, the committee
has added some of the high-level language features that help protect pro-
grammers from the consequences of their errors. The version of C emerging
from the deliberations of this committee will be more powerful than ever.
This book, QuickC itself, and most new C compilers will conform to the
draft version of the ANSI standard.

Using C
Getting a C program from idea to completion takes several steps, with each
step modifying or extending your program. In the next chapter you'll learn
how to write C
programs and get them to run using QuickC. This section
summarizes the main components of a C program and the major tasks
involved in getting from your text file to a running program. We'll see that
QuickC puts the tools for accomplishing various tasks under one program
Using QuickC

"shell." This makes it easy to move from one phase of the program creation
process to another.
When you create a C program, various types of files are created and used.
These include: source and header files created with a text editor; library and
other object files, linked with the compiled version of your main program file;
and an executable file that runs the program.
The first step is to create the program in text form — this is the source file.

The following listing is an example of a source file for a C program:

/* Sample C source file.


This program adds two numbers and writes the sum to the screen.
•/

#include "proginlo.h" /* file containing program specific information */

main () /* main program function */

int result: /* definition of an integer variable, named result */


printf ( "'/.s\n", PROG.MESSAGE) ;

il = 7 + 9; /* add 7+9. assign sum to result */


printf { "sum = '/,d\n" , result); /* write result to screen */
}

The output from this program is

The file contains the main program, niain( ), which calls printf( ), as did
our first example. There is also an instruction (#include "proginfo.h") to read
the contents of a header file, proginfo.h.
There are several new features. Notice that this program also writes
numerical information, the value of variable il. The %d (for decimal) place-
holder indicates this fact. In the second call to printf( ), the value to be
substituted is the value of il, which is 16 after the addition is carried out.
The second argument, information passed to printf(), is substituted for
the placeholder in the function's first argument. This simple replacement
strategy extends to handle additional arguments, as you'll soon see.
The program also illustrates how to define a variable in C, that is, how to
associate a data type with a variable name. (If you're not used to working with
data types, and are not sure what they are, don't worry. Data types are
explained in Chapter 3.) The variable il is defined to be of type int, for integer.
Introducing C

Finally, the statement,

assigns the result of adding 7 and 9 to the variable il. You'll learn about
variable definition and assignments in Chapter 3.

Compiling and Linking


The source file containing the listing is processed by the QuickC compiler,
which creates another version of the file by translating your program into
another form. During compilation, QuickC reads the header file proginfo.h
and makes the requested substitutions and definitions.
Source files include definitions for the functions you need in your pro-
gram, and may include definitions of variables used by multiple functions in
your program. There may also be instructions to read additional header or
other files. Your program will have one main source file, and may have
additional include files.

Header files are ordinary text files either written by you or provided with
the compiler. These files generally contain information needed for specific
tasks on a particular machine or with a particular compiler. Associated with
this information are mnemonic names, which are easier to remember than

obscure numerical values. When you use these names, the compiler substitutes
the values it finds for each name in the header files. For example, the header
file, proginfo.h, may contain the following:

/• Partial contents of file, proginfo.h. */

#define PROG.NAME "QuickC version 1.0" /* C version name */


•define MAX.INT 32767 /* largest integer value in system */
#define FALSE /* value to substitute when test is false */

The second statement provides a name for the largest integer represented
on the system. This name is much more meaningful than the actual number,
which may vary from machine to machine. When the compiler sees MAX
INT in the source file, it substitutes the value 32767. In the third instance, the
compiler substitutes the numerical value when you use false in your program.
(Later, you will see how C represents true and false.)
Such substitutions work out well for you and your program. You can use
.

10 Using QuickC

meaningful and easy-to-remember names. The compiler substitutes actual


values, so it need not look up the value associated with the name you used, as
would be necessary with variables. This makes your program run faster.
The compiler produces an object file that contains your program (as well
as other information) in a form more readily understood by the machine on
which the program runs. Your program may use functions that have already
been defined for you, or that you have defined elsewhere, compiled, and saved
in a separate file. A linker program combines the recently compiled object file

with function library files and other precompiled (object) files. The outcome of
this linking process is the program itself often known as an executable file.

Library Files

It is common among C programmers to build and use precompiled library files


containing commonly used functions. These functions are linked with a
program only if they are needed. This approach has several advantages. When
writing the program, you need not write the functions because they are already
written and available. When compiling, you need not compile the functions
each time because they are already compiled. This saves time, since the
compiled source file being composed is shorter.
Function libraries or modules make programs
it easier to build portable
because system-dependent functions can be collected in modules isolated from
system-independent functions. To move to a new system, only the modules
containing system-dependent functions need to be rewritten or replaced. The
new version can then be linked into your program after it has been recompiled
for the new system. Later, we will discuss library files and look at some of the
most commonly supplied functions. To summarize, a C program consists of
the following basic components:

1 Source files created with an editor and processed by the compiler. One
of these files contains the main program function, main( ). Every C
program must have at least one source file.

2. Optional header files, which may contain various values and defini-
tions for the program or the environment.

3. Library files and other object files, which are linked with your com-
Introducing C 11

piled program files at the appropriate point in the program develop-


ment process.

4. An executable file.

^REMEMBER
• There must be at least one source file — otherwise you have nothing to
compile or run.

• There must also be a function called inain( ) somewhere in the source


files.

• The program starts executing at main( ).

All files other than source files — headers, libraries, and so forth — are
optional.Whether you need such files, and how you add them, depends on the
C compiler you are using and the tasks you are trying to accomplish in your
program.
If all goes well, and the compilation and linking processes take place
without error, your program will be ready to run. Of course, that's often when
the real fun begins, when you discover the surprising things you've uninten-
tionally instructed your program to do.

^REMEMBER There are three steps in creating a C program:

1. Creating source file(s)

2. Compiling the source file(s)

3. Linking the resulting object file with whatever libraries and additional
modules are needed

Why QuickC?
QuickC makes it easy to carry out the steps required for C programming in a
flexible manner, within a tightly integrated and powerful environment. The
QuickC system provides a shell within which you can easily move from one
12 Using QuickC

Step to another when creating and testing your program.


You can edit, compile, link, debug (watch your program as it runs,
looking for errors, or bugs), and execute your program, all within QuickC.
Moreover, QuickC lets you specify options for any of these phases. This is very
easy to do with QuickC. For example, it takes just a single keystroke to tell

QuickC to optimize the program for speed (at program size); or you
the cost of
can ask it to warn you about any questionable programming practices, such as
constructs that violate the official language definition.
If you are used to writing programs, you know the tedium involved in
fixing small errors as the compiler encounters them. You must stop the
compilation, call up your editor, change your file, save it, call up the compiler,

find the next error, and so on.


In QuickC, all of this can be done within one program. After you have
created your source QuickC
you compile, link, and run it in just a few
file, lets

keystrokes. If there are any problems with the program, QuickC puts you back
You can edit the file, then tell QuickC
in the source file at the appropriate place.

to continue. The system then recompiles, relinks, and reruns the revised
program.
QuickC's integrated environment is also convenient for debugging. You
can trace the program's execution using the debugging facility. If a change is

needed, simply make QuickC to continue. Again, a few keystrokes


it, then tell

will get the system to reprocess your program and run it again, but this time in

debugging mode.
QuickC comes "preloaded" with many functions defined in separate
libraries by other C implementations. This gives you access to a more powerful
C without forcing you to link in separate libraries to get this power.
QuickC does its work quickly. In the next chapter, we will look
Best of all,
at the QuickC environment and explore it with a few sample programs.

Throughout the book, you will learn ways of taking particular advantage of
QuickC's environment.
A Quick Look
at QuickC

Microsoft's QuickC is a very powerful integrated program development


environment, which includes an editor (for creating your program files), a
compiler (for translating your programs into a form understandable to the
computer), and a debugger (for tracing the execution of your program to
identify errors in it). These components are all accessible within the QuickC
shell, so you can switch between them quickly. A linker is also available for use
by QuickC and as a separate program. There are many additional features,
such as on-line help, that make QuickC even nicer to use.
This chapter provides two kinds of information. The first half presents an
informal introduction to some of QuickC's features. You'll learn how to use
QuickC to create, compile, watch, and run your programs. This section is
designed to give you a chance to explore the most commonly used features of

13
14 Using QuickC

QuickC. It is by no means an exiiaustive discussion. Its purpose is to give you a


feel for C programs with QuickC. You may want to
what's involved in building
use the QuickC command summary in Appendix C as a supplement to this
in