! (not) logical operator, 125–130
!= (not equal to) operator, 114
#define directive, 76–78
#include directive, 72–75
placement, 75–76
#include statement, 19
% (modulus) operator, 93
random values, 213
%= (compound modulus) operator, 107
& (ampersand)
address-of operator, 258–260
pointer variables, 85
scanf( ) function, 85
&& (and) logical operator, 125–130
’ (apostrophe), character data, 20
“” (quotation marks), character data, 21
(( )) parentheses, order of operators, 96
* (asterisk)
dereferencing operator, 258–261
multiplication operator, 92
*= (compound mulitiplication) operator, 106
+ (addition) operator, 92
++ (increment) operator, 138–140
+= (compound addition) operator, 106–107
- (subtraction) operator, 92
-- (decrement) operator, 92, 138–140
-= (compound subtraction) operator, 107
-> (structure pointer) operator, 299
/ (division) operator, 92–93
// (double slash), comments, 33–34
/= (compound division) operator, 106
; (semicolon)
commands, 40
for loops, 162
functions, 40
statements, 118
< (less than) operator, 114
<= (less than or equal to) operator, 114
<> (angled brackets), #include files, 73
= (equal sign), assignment operator, 54–55
== (equal to) operator, 114
> (greater than) operator, 114
>= (greater than or equal to) operator, 114
?: (conditional) operator, 136–138
[] (brackets), character arrays, 63
“ (quotation mark) escape sequence, 41
\ (double backslash), escape sequence, 41
{} (braces), main( ) function, 19
|| (or) logical operator, 125–130
a (alarm) escape sequence, 41–42
absolute value, 209–211
addition (+) operator, 92
address-of (&) operator, 258–260
addresses
memory, 256–257
variables, 259
allocating heap memory, 282–285
with arrays of pointers, 286–288
alphabetizing characters, 246
ampersand (&)
pointer variables, 85
scanf( ) function, 85
and (&&) logical operator, 125–130
ANSI C, 11
apostrophe (’), character data, 20
arguments
conditional (?:) operators, 136–138
decrement (--) operators, 138–140
expressing in radians, 211–212
fopen( ) function, 311
increment (++) operators, 138–140
passing, 344–345
by value, 345–347
arrays, 62
character, 62–65
initializing, 222–225
scanf( ) function, 86–87
string concatenation, 200–202
string length, 269–271
filling, 232–237
floating-point, 224
integer, 266
names, 266–268
numeric, 225–226
of pointers, 271–273
heap memory allocation, 286–288
of strings, 272–273
of structure variables, 299–300
parallel, 233
passing by address, 347–351
printing, 190
referencing, 266
sorting, 242–250
storing string values in, 63
values
storing in, 226–227
swapping, 244–246
ASCII table, 380–389
assigning values
to strings, 268–269
to variables, 97
assignment (=) operator, 54–55
assignment operators, 97
binary states, 9
Blackjack program, 372–378
Borland C++, 8
braces ({}), main( ) function, 19
brackets ([]), character arrays, 63
break statements, 170–172
including in switch statements, 180–181
bubble sorts, 242–246
%c (character) conversion character, 43
C compilers, 8–9
ANSI C, 11
debugging with, 10
editors, 9
screen clearing functions, 152
calculations
absolute value, 209–211
converting non-integers into integers, 208–209
logarithmic functions, 211–213
negative values, 92
numeric functions, 208–209
operators, 92–94
logical, 124–130
parentheses (( )), 96
precedence order, 94–96
relational, 114–116
right-to-left associativity, 97
powers, 210–211
random values, 213–214
square roots, 210–211
trigonometric functions, 211–213
calling
functions, 334–336
strings, 201–202
case sensitivity
character input, 199
commands, 17
functions, 17–18
case statements, 181
ceil( ) function, 208–209
char variable, 51
character (%c) conversion character, 43
character arrays, 62–65
brackets ([]), 63
initializing, 222–225
printing, 190
scanf( ) function, 86–87
strings
concatenating, 200–202
length, 269–271
values, swapping, 244–246
character functions
character-changing, 199–200
character-testing, 198–199
character I/O functions, 188–194
getch( ), 193–194
getchar( ), 188–192
gets( ), 201–202
isalpha( ), 198–199
isdigit( ), 198–199
islower( ), 199
isupper( ), 199
putchar( ), 188–191
puts( ), 201–202
tolower( ), 199–200
toupper( ), 199–200
characters, 20–21
alphabetizing, 246
ASCII table, 380–389
conversion, 43–44
scanf( ) function, 83
input, 188–191
case sensitivity, 199
pointer variables, 270
strings, 21
printing, 40–41
scanf( ) function, 86–87
clearing screen, 152–153
closing files, 311
random-access, 321
code, see source code
commands
case sensitivity, 17
semicolon (;), 40
commenting out source code, 32
comments, 28–30
example, 31
future of, 33–34
syntax, 30
white space, 32–33
comparing
loops, 160
values, 114–116
compiling programs, 8
compound addition (+=) operator, 106–107
compound assignment operators, 104–107
precedence order, 107–108
compound division (/=) operator, 106
compound modulus (%=) operator, 107
compound multiplication (*=) operator, 106
compound relational operators, 124
compound statements, 116
compound subtraction (-=) operator, 107
concatenating strings, 200–202
conditional (?:) operators, 136–138
constant data, 50
constants
defining, 76–78
named, 76
context-sensitive help, 74
continue statements, 172–174
controlString, 39
conversion characters, 43
escape sequences, 41
conversion characters, 43–44
scanf( ) function, 83
converting
floating-point values to integers, 284
non-integers to integers, 208–209
cos( ) function, 211
counter variables, 104
loops, simulating, 160
%d (integer) conversion character, 43
data
inserting in structures, 299–301
testing, 114–116
if statements, 116–117
if-else statements, 117–119
data types
characters, 20–21
floating-point numbers, 22–23
integers, 21–23
return, 359–360
typecasting, 108–109
values, 140–141
deallocating heap memory, 282, 286
debugging, 10
decimal points (floating-point numbers), 22–23
declarations, variables, 52–53
decrement (--) operator, 92, 138–140
decrementing variables, 105, 139–140
#define directive, 76–78
defining
character, 63
of structure variables, 299–300
subscripts, 225
constants, 76–78
file pointers, 309–310
floating-point pointer variables, 258
floating-point variables, 258
integer arrays, 266
integer pointer variables, 258
integer pointers, 282
integers, 258
members, 296
pointer variables, 257–260
pointers to structures, 299
structures, 294–299
variables, 52–53
int, 295
multiple, 53
program design, 336–338
structure, 294–298
degrees, expressing arguments in, 212
dereferencing (*) operator, 258–261
dereferencing pointers, 260–261
directives
#define, 76–78
#include, 72–75
placement, 75–76
preprocessor, 72
disk files, see files
dispTitle( ) function, 152
division (/) operator, 92–93
do-while loops, 153–154
continue statements, 172–174
terminating, 170–172
dot operator, 299–301
double variables, 51
editing sequential-access files, 314–315
editors, 9
Enter keypress
converting to null zero, 202
eliminating
with getch( ) function, 193–194
with getchar( ) function, 191–192
equal sign (=), assignment operator, 54–55
equal to (==) operator, 114
errors, debugging, 10
escape sequences, 41–42
scanf( ) function, 83
executing programs, 7
exit( ) function, 180
exp( ) function, 212
expressions
decrement operators, 139
increment operators, 139
operators, 92
order of, 94–96
parentheses (( )), 96
typecasts, 109
values, 97
%f (floating-point) conversion character, 43
fabs( ) function, 209–210
fclose( ) function, 311
feof( ) function, 313–314
fgets( ) function, 271, 312–314
file pointers, 309–310
files, 308–309
closing, 311
creating, 311
header, 74–75
merges, 72–75
MYDATA.DAT, 312–315
names, 309
opening, 309–311
outputting characters to, 324
random-access, 309
closing, 321
creating, 321
fopen( ) function modes, 321–322
navigating, 322–325
opening, 320–322
writing to, 323–324
reading, 311
sequential-access, 309
editing, 314–315
navigating, 323
reading, 312–314
writing to, 312
flag variables, 236
float variables, 51
floating-point (%f ) conversion character, 43
floating-point arrays, 224
floating-point numbers, 22–23
absolute values, 209–211
conversion characters, 44
floating-point values, converting to integers, 284
floating-point variables, 258
floor( ) function, 208–209
fopen( ) function, 309–311
arguments, 311
random-access modes, 321–322
for loops
arrays of strings, 272–273
continue statements, 172–174
counting down, 163–165
format, 160–162
indents, 161
nesting, 164
simulating with counter variables, 160
source code, repeating, 160–163
terminating, 170–172
formats
#include directive, 72
loops
do-while, 153
for, 160–162
while, 150
operators
conditional, 136–137
dot, 299
placeholders, 39
printf( ) function, 38–40
program design
functions, 332–336
variables, 336–338
statements
break, 170
if, 116–117
struct, 295
switch, 178
typecasts, 108–109
free heap, 278
free( ) function, 286
fscanf( ) function, 314
fseek( ) function, 322–325
functions, 17–19
calling, 334–336
case sensitivity, 17–18
ceil( ), 208–209
character I/O, 188–194
getch( ), 193–194
getchar( ), 188–192
gets( ), 201–202
isalpha( ), 198–199
isdigit( ), 198–199
islower( ), 199
isupper( ), 199
putchar( ), 188–191
puts( ), 201–202
tolower( ), 199–200
toupper( ), 199–200
character-changing, 199–200
character-testing, 198–199
cos( ), 211
dispTitle( ), 152
exit( ), 180
exp( ), 212
fabs( ), 209–210
fclose( ), 311
feof( ), 313–314
floor( ), 208–209
fopen( ), 309–311
random-access modes, 321–322
free( ), 286
fscanf( ), 314
fseek( ), 322–325
getAns( ), 154
gets( ), 357
isalpha( ), 198
isdigit( ), 198
log( ), 212
log10( ), 212
logarithmic, 211–213
main( ), 17–19
program formats, 333
malloc( ), 282–285
numeric, 208–209
passing
arguments, 344–347
arrays, 347–351
placeholders, 39
pow( ), 210–211
printf( ), 38
controlString, 39–41
conversion characters, 43–44
escape sequences, 42
format, 38–40
strings, printing, 40–41
program design, 332–336
prototyping, 360–362
rand( ), 213–214
return data types, 359–360
scanf( ), 82
ampersand (&), 85
conversion characters, 83
escape sequences, 83
printf( ) function prompt, 83–84
troubleshooting, 84–87
semicolon (;), 40
sin( ), 211
sqrt( ), 210–211
srand( ), 214
strcat( ), 200–202
strcpy( ), 66
string, 200–202
strlen( ), 189
tan( ), 211
trigonometric, 211–213
values, returning, 356–358
getAns( ) function, 154
getch( ) function, 193–194
getchar( ) function, 188–192
gets( ) function, 201–202, 357
global variables, 53
passing, 362
program design, 336–338
returning, 362
greater than (>) operator, 114
greater than or equal to (>=) operator, 114
header files
#include directive, 72–75
structures, reusing, 297
heap memory, 278–281
allocating, 282–285
with arrays of pointers, 286–288
shortage of, 285
structures, 299
heap structures, 300–301
help, 74
I/O functions, see character I/O functions; input; output
if statements, 114–117
logical operators, 125–130
precedence order, 130–132
nesting, 178
if-else statements, 117–119
conditional operators, 137–138
#include directive, 72–75
placement, 75–76
#include statements, 19
increment (++) operator, 138–140
incrementing variables, 105, 139–140
indents
for loops, 161
source code, 17
infinite loops, 150
character, 222
integer, 266
of strings, 272–273
strings, 65–66
input
character-changing functions, 199–200
character-testing functions, 198–199
Enter keypress, eliminating
with getch( ) function, 193–194
with getchar( ) function, 191–192
scanf( ) function, 84–87
inserting data in structures, 299–301
int * typecast, 284
integer (%d) conversion character, 43
integer arrays, 266
integer division, 93
integer pointers
defining, 282
variables, 258
integers, 21–23
converting
floating-point values to, 284
non-integers into, 208–209
defining, 258
division (/) operator, 93
leading zeros, 22
negative values, 209
isalpha( ) function, 198
isdigit( ) function, 198
islower( ) function, 199
isupper( ) function, 199
iteration, 172–173
keyboard
character input, 188–191
Enter keypress, 202
keywords, variables, 51
leading zeros, 22
less than (<) operator, 114
less than or equal to (<=) operator, 114
literal constants
decrement operators, 139
increment operators, 139
literal data, 50
local variables, 53
program design, 336–338
log( ) function, 212
log10( ) function, 212
logarithmic functions, 211–213
logical operators, 124–130
precedence order, 130–132
long int variable, 51
loops, 150
break statements, 170–172
comparing, 160
continue statements, 172–174
counting subscripts with, 227
do-while, 153–154
for
counting down, 163–165
format, 160–162
indents, 161
printing arrays of strings, 272–273
simulating, 160
source code, repeating, 160–163
infinite, 150
nesting, 164
terminating, 170–172
while
format, 150
simulating, 160
source code, repeating, 152–153
variables, 151
machine language, 9
main( ) function, 17–19
braces ({}), 19
program formats, 333
malloc( ) function, 282–285
members
defining, 296
structures, 294
memory
addresses, 256–257
allocating with pointer variables, 280
data type values, 140–141
floating-point numbers, 22–23, 140–141
heap, 278–281
allocating, 282–288
shortage of, 285
structures, 299
merges
character arrays, 200–202
files, 72–75
modulus (%) operator, 93
random values, 213
multiplication (*) operator, 92
(newline) escape sequence, 41–42
names
arrays, 266–268
constants, 76
disk files, 309
pointer variables, 258
structure variables, 299
variables, 51–52
storing pointers, 260
navigating files
random-access, 322–325
sequential-access, 323
negative values, 209
calculating, 92
nesting
if statements, 178
loops, 164
statements, 124
not (!) logical operator, 125–130
not equal to (!=) operator, 114
null values, 285
null zero, 60–62
converting Enter keypress to, 202
numeric arrays, 225
strcpy( ) function, 66
numbers, 21–23
absolute values, 209–211
conversion characters, 43–44
floating-point, 22–23
integers, 21–23
isdigit( ) character-testing function, 198
raising to powers, 210–211
square roots, 210–211
numeric arrays, 225–226
numeric functions, 208–209
numeric values, reading, 314
opening files, 309–311
random-access, 320–322
operators, 92–94
addition (+), 92
assignment, 97
assignment (=), 54–55
compound assignment, 104–107
precedence order, 107–108
conditional (?:), 136–138
division (/), 92–93
dot, 299–301
expressions, 92
increment (++), 138–140
logical, 124–130
precedence order, 130–132
modulus (%), 93
random values, 213
multiplication (*), 92
pointer, 258–260
precedence order, 94–96
relational, 114–116
combining, 124–130
right-to-left associativity, 97
structure pointer (->), 299
subtraction (-), 92
or (||) logical operator, 125–130
order of operators, 94–96
compound assignment, 107–108
logical, 130–132
output, 7
characters, 188–191
conversion, 43–45
printf( ) function, 38–40
sending strings to screen, 201–202
writing to printers, 315
parallel arrays, 233
parentheses (( )), order of operators, 96
passing
arguments, 344–345
by value, 345–347
arrays, 347–351
global variables, 362
placeholders, 39
pointer constants, 266
pointer operators, 258–260
pointer typecasts, 284
pointer variables, 268
ampersand (&), 85
defining, 257–260
memory allocation, 280
names, 258
pointers
array names, 266–268
arrays of, 271–273
heap memory allocation, 286–288
defining, 299
dereferencing, 260–261
file pointers, 309–310
heap values, 282
integer pointers, 282
storing, 260
postfix decrement operator, 139–140
postfix increment operator, 139–140
pow( ) function, 210–211
prefix decrement operator, 139–140
prefix increment operator, 139–140
preprocessor directives, 72
printers, writing output to, 315
printf( ) function, 38
controlString, 39
escape sequence, 41
conversion characters, 43–44
escape sequences, 42
format, 38–40
strings, printing, 40–41
printing
arrays, 190
of strings, 272–273
conversion characters, 43–44
values, 43
programmers, 6
programs
Blackjack, 372–378
comments, 28–30
compiling, 8
data types, 19–23
debugging, 10
definition, 6–7
design
functions, 332–336
variables, 336–338
executing, 7
output, 7
overview, 16–17
running, 7
source code, 9
terminating, 180
white space, 32–33
writing, 9–10
prompts, scanf( ) function, 83–84
prototyping functions, 360–362
putchar( ) function, 188–191
puts( ) function, 201–202
quotation marks (“”), character data, 21
radians, expressing arguments in, 211–212
rand( ) function, 213–214
random values, 213–214
random-access files, 309
closing, 321
creating, 321
fopen( ) function modes, 321–322
navigating, 322–325
opening, 320–322
writing to, 323–324
random-number generator, seeding, 214
reading
files, 311–314
numeric values, 314
strings, 271
records, 294
referencing arrays, 266
relational operators, 114–116
combining, 124–130
remainders (integer division), 93
repeating source code
with for loops, 160–163
with while loops, 152–153
return data types, 359–360
returning
global variables, 362
values, 356–358
prototyping functions, 360–362
running programs, 7
%s (string) conversion character, 43
scanf( ) function, 82–83
ampersand (&), 85
conversion characters, 83
escape sequences, 83
printf( ) function prompt, 83–84
troubleshooting, 84–87
screen
character output, 188–191
clearing, 152–153
sending strings to, 201–202
searches, arrays, 233–237, 246–250
seeding random-number generator, 214
commands, 40
for loops, 162
functions, 40
statements, 118
sequential searches, 237
sequential-access files, 309
editing, 314–315
navigating, 323
reading, 312–314
writing to, 312
sharing variables, 344
sin( ) function, 211
sizeof( ) function, 140–141, 226
sorting arrays, 242–250
source code, 9
commenting out, 32
comments, 28–30
indents, 17
repeating
with for loops, 160–163
with while loops, 152–153
sqrt( ) function, 210–211
square roots, 210–211
srand( ) function, 214
statements
case, 181
compound, 116
continue, 172–174
if, 114–117
logical operators, 125–132
nesting, 178
if-else, 117–119
conditional operators, 137–138
#include, 19
nested, 124
semicolon (;), 118
struct, 295–296
switch, 178–181
storing
pointers, 260
strings, 269–271
values
variables, 54–55
strcat( ) function, 200–202
strcpy( ) function, 66
string (%s) conversion character, 43
string functions, 200–202
strings
arrays of, 272–273
calling, 201–202
characters, 21
concatenating, 200–202
initializing, 65–66
null zero, 60–61
reading, 271
scanf( ) function, 86–87
terminating, 60–61
values
assigning to, 268–269
printing, 43
storing in arrays, 63
strlen( ) function, 189
struct statement, 295–296
structure pointer (->) operator, 299
structures, 294
defining, 294–299
heap memory, 299–301
members, 294
defining, 296
pointers to, 299
reusing, 297
variables
arrays of, 299–300
defining, 294–298
inserting data, 299–301
names, 299
referencing, 266
subtraction (-) operator, 92
swapping values (variables), 244–246
switch statements, 178–180
break statements, 180–181
switch variable, 180
syntax, comments, 30
(tab) escape sequence, 41–42
tan( ) function, 211
terminating
loops, 170–172
programs, 180
strings, 60–61
testing
data, 114–116
if statements, 116–117
if-else statements, 117–119
values, multiple, 136–138, 178
tolower( ) function, 199
toupper( ) function, 199
trigonometric functions, 211–213
troubleshooting scanf( ) function, 84–87
true/false results, 114–116
unallocated heap memory, 278
updating variables, 104–107
user input, scanf( ) function, 84–87
values
absolute, 209–211
arrays
filling, 232–237
sorting, 246–250
assigning
to strings, 268–269
to variables, 97
comparing, 114–116
data types, 140–141
decrementing, 105
expressions, 97
floating-point, 284
incrementing, 105
null, 285
numeric reading, 314
printing, 43
random, 213–214
returning, 356–358
prototyping functions, 360–362
sorting, 242–246
storing
in arrays, 226–227
in variables, 54–55
strings, 63
testing, multiple, 136–138, 178
variables
changing, 104–107
passing by, 345–347
swapping, 244–246
variables
addresses, 259
assignment operators, 54–55
char, 51
character arrays, 62–65
character pointer, 270
counter, 104
simulating loops, 160
data types, 108–109
declarations, 52–53
defining, 52–53
double, 51
file pointer, 309–310
flag, 236
float, 51
floating-point, 258
integer pointer, 258
keywords, 51
long int, 51
names, 51–52
pointer, 268
ampersand (&), 85
defining, 257–260
memory allocation, 280
names, 258
program design, 336–338
sharing, 344–351
structure
arrays of, 299–300
defining, 294–298
inserting data, 299–301
names, 299
switch, 180
types, 50–51
updating, 104–107
values
assigning, 97
changing, 104–107
storing, 54–55
swapping, 244–246
while loops, 151
Visual C++, 8
while loops
continue statements, 172–174
format, 150
simulating, 160
source code, repeating, 152–153
terminating, 170–172
variables, 151
white space, 32–33
writing
output to printers, 315
programs, 9–10
to files
random-access, 323–324
sequential-access, 312
zeros
leading, 22
null, 61–62
converting Enter keypress to, 202
strcpy( ) function, 66