Professional Documents
Culture Documents
Програмски јазик C Programiranje Kniga
Програмски јазик C Programiranje Kniga
II 16945
db142
.
.
'-' tamina
(. dp . G5,2.JS11
cwr
z.
.;l~.
..-
.,
500 , ,
,
".
.
.
Authorized translation from the English language edition, entitled PROGRAMMING LANGUAGE,
2nd Edition, 0131 103628 by KERNIGHAN, BRIAN W.; RICHIE, DENNIS, published by Pearson
Education, lnc, publishing Prentice Hall, Copyright 1988, 1978 by Bell Telephone Laboratories,
lncorporated, by Prentice Hall, lnc., Upper Saddle River, NJ 07458
All the rights reserved. No part of this book may be reproduced or transmitted in any form or by
any means, electronic and mechanical, including photocopying, recording or by any information
storage retrieval system, without permission from Pearson Education, lnc. MACEDONIAN language
edition published by ARS LAMINA DOO, Copyright 2009
,
2009,
:
-
CIP-
. . ~
004.432. 2
, .
. , . . -
ISBN 978-08-4535-48-5
1. . . . . . 2. , . [avtor]. 1. Kerighan, Brian W. , .
.,..,...- ~ - ( )
/
.. COB~SS.MK-ID 80939530
._ ...
,ff;;~f:J.!:' ~r}.
. p{p_/:.l!J
5jr. rp
42.
,2 ~ 01
/2otto
xi
xii
r 3
5
5
8
1 - 3
1.1
1.2
1.3 for
1.4
1.5
1.5.1
1.5.2
1.5.3
1.5.4
1.6
1.7
1.8 -
1.9
1.1
2 - , 33
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
2.1
2.11
2.12
14
16
17
17
19
21
22
24
27
31
32
35
41
41
42
43
47
48
49
50
54
57
59
61
62
Vl
-
3.1
3.2 if- else
3.3 else- if
3.4 switch
3.5 - while for
3.6 do- wh ile
3.7 break continue
3.8 goto
4- nporpaa
4.1
4.2
4.3
4.4 (. )
4.5 3
4.6
4.7
4.8
4.9
4.1
4.11
4.11.1
4.1 1.2
4.11.3
-
5.1
5.2
5.3
5.4
5.5
5.6 ;
5.7
5.8
5.9
5.1
5.11
5.12
6-
6.1
6.2
6.3
65
65
65
67
69
71
74
76
77
79
79
83
86
93
95
97
98
98
99
101
103
106
104
107
109
109
111
114
117
121
125
129
132
133
134
139
142
149
149
152
155
6.4
6.5 -
6.6
6.7 typedef
6.8
6.9
160
162
168
170
172
174
7 - n n
7.1
7.2 - printf
7.3
7.4 - scanf
7.5
7.6 - stderr exit
7.7
7.8
7.8.1
7.8.2
7.8.3 ungetc
7.8.4
7.8.5
7.8.6
7.8.7
177
177
179
182
183
187
190
192
194
194
194
195
195
195
196
197
8- UNIX
8.1
8.2 1/0- read write
8.3 open, creat, close, unlik
8.4 - elseek
8.5 - fopen getc
8.6 -
8.7 - (3)
199
199
200
202
205
206
21
216
1
2
2.1
2 . 2
2.3
2.4
2 .5
2.5 . 1
2.5 .2 3
2.5.3
223
223
223
223
224
224
224
225
225
226
227
Vlll
2.5.4
2.6
3
4
4.1
4.2
4.3
4.4
5
6. 1 ()
6.2
.
.4
6.5
.
6.7
void
6.8
void
7
7.1
7.2
7.3
7.3.1
7.3.2
7.3.3
7.3.4
7.4
7.4.1
7.4.2
7.4.3 ()
7.4.4
7.4.5
7.4.6
7.4.7
7.4.8
7.5
sizeof
(casts)
7.6
7.7
7.8
7.9
7.1
7.11
7.12
7.13
227
227
228
228
228
229
230
230
231
231
231
231
232
232
232
233
234
234
235
235
236
236
237
237
238
239
239
239
240
240
240
240
241
241
241
241
242
242
243
243
244
245
245
245
7.14
7 . 15
7 . 1
7.17
7.18
7.19
8
8 . 1
8.2
8.3
8.4
8.5
8 .6
8.6.1
8.6.2
8 .6.3
8.7
8 . 8
8 .9 typedef
8 . 1
9
9.1 (.
labeled)
9.2
9.3
9.4
9.5
9.6
1
10.1
10.2
11
11.1
11 .2
12
12.1
12.2
12.3
12.4
12.5
12.6
12.7
12.8
pragma
12.9
12.1
245
246
246
246
247
248
248
249
250
25 1
255
256
257
257
258
259
261
263
264
265
266
266
266
267
267
268
269
270
270
272
273
273
274
275
275
276
276
279
279
281
28 1
281
282
282
13
-
<stdio.h>
1.1
1.2
1.3
1.4
282
1 :
1.5
1 .6
1.7
2 :
<ctype.h>
<string.h>
4 : <math.h>
: <stdlib.h>
: <assert.h>
7 : <stdarg.h>
8 : <setjump.h >
9 : <signal.h >
1 : <time.h>
11 n: <limits.h> <f1oat.h>
3 :
291
29 1
292
294
297
299
300
300
30 1
302
302
304
305
308
309
309
31
311
313
317
321
"
1978 ,
. ,
. ,
,
UNIX.
, ,
,
,
.
1983 ,
National Standard lnstitute - ANSI) ,
" -
". ANSI .
(a.A merican
,
,
.
. , ,
, ,
, .
,
,
.
"
ANSI .
, .
;
.
.
.
, .
, -
Xl
xii
.
. ,
,
.
, .. .
, , ,
.
,
.
. , ,
, .
.
"
".
, .
.
. , ,
.
, , , .. , ,
, , , , ,
.
, , , ,
, , .
++
ANSI .
ANSI
.
.
.
.
.
, ,
UNIX
DEC PDP - 11, . ,
UNIX-o (
) . ,
IBM System/370,
Honeywell 6000 lnterData 8/ 32. , ,
,
.
. ,
,
. ,
, .
, ,
. ,
.
, , ,
.
;
, . , , ,
n ,
.
,
. ,
X lll
xiv
.
, , , , , ,
. ,
, , , , , ,
, , , , , ,
, , , , ,
.
.
.
UNIX
UNIX
. , ,
();
,. "
.
BePL .
BePL
UNIX
1970
DEC PDP-7.
BePL ., ".
. ,
. ,
, , .
;
, (
). - .
: , (if-
(break).
, ,
, . .
., ",
. , ,
.
,
.
, (
) .
,
" ".
,
, , .
.
( ) , , .
,
.
(. stack), ;
(. heap) (. garbage collection). ,
/ ; READ WRITE ,
.
.
.
, , : , ,
, , ,
(",
?"),
. ,
. ,
.
,
.
(ANSI)
198
. AN$1 , ANSI
1988 .
.
.
;
, ,
, .
,
.
;
.
; ,
, , .
.
, .
.
.
. (
, ), ,
, .
,
.
, .
" /
" UNIX .
, , . ,
.
.
,
.
, ,
.
, ..
.
,
.
, ,
. ,
;
, .
, , .
,
. ,
;
.
; .
,
.
1,
. ,
,
. , ,
;
, ,
n=n+l. ,
, ,
;
, .
2
1,
, . 2
, . 3
: if-else , switch, while , for .
4 -
,
, , - , ,
.
. .
7 ,
ANSI ,
, /
.
8
UNIX, / ,
UNIX ,
.
.
ANSI .
. ,
, .
.
. , ,
.
1: 3
, ,
. , ,
( )
, ,
: , , , ,
.
.
, ,
,
.
.
,
, , .
,
.
.
.
,
, .
, .
1.1
2.
. , :
hello, world
: ,
, , ,
. ,
.
"Hello, world"
#include <stdio.h>
main()
{
printf("hello, world\n");
.
,
UNIX
hello.c
,
. out. . out
a.out
hello, world
. ,
, . ()
,
, .
main. ,
, "main" -
main.
" main" .
main
; ,
101
#include<stdiooh>
,
1 ;
7
, ,
,
,
main
()
#include <stdiooh>
main ()
main
main i
u
main u
pritf
\n
{ }
main
printf ( " hello, world \ n " ) ;
,
,
printf
\n,
"hello ,
,
world
\ n ",
printf
\n
( )
. \n
,
printf ;
printf ,
,
#inelude <stdio.h>
main()
{
\n .
\n
\ t , \b , \ "
\\ (. backslash) .
2 . 3
1-1 .
"Hel1o,
world"
1-2 .
printf \,
.
1.2
= (5/ 9) (F-32)
:
1.2
-17
20 -6
40 4
60 15
80 26
100 37
120 48
140 60
160 71
180 82
200 93
220 104
240 115
260 126
280 137
300 148
#include <stdio.h>
/*
n -
fahr
= ,
20 ,
. .. , 300 */
main ()
{
/*
/*
/*
*/
*/
fahr = lower;
while (fahr <= upper) {
celsius = 5 * (fahr-32) 1 9 ;
printf("%d\t%d\n", fahr, celsius);
fahr = fahr + step ;
/*
n -
fahr
= ,
20 , ... , 300 */
*/
10
, .
/*
* 1
, , .
,
. ,
,
. ;
n,
int
float, , .
. int, floa t
; 16- int , -32678 +32767, ,
32- int. float 32-
, 6 10- 38
10+38
int float, :
;
char
short
long
double
""
""
n
, , . ,
,
. .
lower = ;
upper = 300;
step = 20;
.
("; " ) .
,
;
while
11
102
while : ,
(fahr upper) ,
( )
, , ,
(fahr
upper) ,
,
,
while
, , , ,
while (i < )
i = 2 * i ;
,
while,
( )
( )
celsius :
celsius
=5 *
(fahr-32) 1 9 ;
5/9 , ,
(
truncate)
5 9 , 5/ 9 ,
, , printf
printf ,
7
, %
(, , )
, %d ,
12
ce1sius ,
( \ t)
fahr
% printf
, .
, .
,
printf ;
printf
, .
printf ANSI ,
, .
7 .
. ,
scanf 7 . 4 . scanf
printf ,
.
,
. ;
%d
printf
,
. ,
, ,
20
40
60
-17
-6
4
15
26
100
37
:
, ;
, 0 F -17 . 8 , -17 . ,
, .
:
1.2
include
13
<stdio.h>
/* -
for fahr
main()
=,
- */
/*
/*
/*
*/
*/
*/
fahr
lower;
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf( "%3.0f %6.lf\n", fahr , celsius) ;
fahr = fahr + step ;
fahr
celsius fioat,
5/ 9,
.
,
5 . /9.
,
.
,
.
32
(fahr-32) ,
. ,
,
, .
,
2. 3.
, :
fahr = lower ;
%3. Of ,
fahr)
fioat
printf ,
14
,
. % . l f
(celsius)
- 17 . 8
20
40
- . 7
4.4
: % f
%. 2f
%f , ,
, ;
%d
%d
%f
%f
% 2f
% . 2f
1 2
1 1
printf, , n
: %
, % , % , % %% %.
1-3 .
1-4.
1.3 3 for
. .
#include <stdio.h>
/* print Fahrenheit-Celsius table */
main ()
1.3
for
15
int fahr ;
for (fahr = ; fahr <= 300 ; fahr = fahr + 20)
printf ("%3d %6 .lf\n" , fahr, (5 . 0/9. )* (fahr-32)) ;
, .
fahr, int.
for , ,
printf , .
-
,
printf
%6. lf,
.
for
while .
while, ,
for
, . ,
-. ,
fahr
, .
:
printf )
fahr
= fahr
+ 20
, , .
. while,
, , .
, , .
for while , .
, for
, while ,
.
16
1-5 .
1 . . 300 .
1.4
. "
"
300
20
. ,
.
tdefine
idefine
, ( )
, .
:
. ;
.
tinclude <stdio.h>
idefine LOWER
1*
idefine UPPER 300 /*
tdefine 20
/*
/* 'l'
ma.in ()
I 'l'aena'l'a
I
*/
*/
*/
'l'- 'l'
*/
int fahr ;
for (fahr = LOWER ; fahr <= UPPER; fahr = fahr + )
printf ("%3d %6 . lf\n" 1 fahr , (5 . 0/9.0)*(fahr-32)) ;
LOWER , UPPER
, ,
#define ,
-.
1.5
17
streams)
;
.
;
.
. ,
getchar putchar
getchar
. . .,
= getchar () ;
.
; 7 .
putchar
putchar(c) ;
,
.
putchar printf ;
1.5.1
getchar putchar ,
.
, .
while ( )
18
#inelude <stdio.h>
/*
ain
1- */
()
int
getehar () ;
while ( != EOF)
putehar(e);
= getehar () ;
" ".
, ,
.
cha.r
. int , .
getehar
, v. t.
. EOF, "
(. end of file)".
getchar . t.
char npani BOF
ehar. int.
. , ,
= getchar ()
.
.
while ,
1.5
19
#inelude <stdio.h>
n ,
/*
2-
*/
main()
{
int
while
. ,
while
while .
, while , main .
, .
qetehar -
, ,
. .
(, ,
,
.)
, . ! =
=,
! =. ,
= qetehar()
!= EOF
= (qetehar()
!= EOF)
qetehar
( 2.)
1,
1- . qetehar ()
1-7.
! = EOF 1 .
EOF.
20
1.5.2
#include <stdio.h>
/*
main()
1-
*/
long nc ;
nc = ;
while (getchar() != EOF)
++nc ;
printf( "%ld\n", nc) ;
++nc ;
,
++ ,
). nc
= nc
+ 1, ++nc ,
--
{ ). ++ --
(++nc)
(nc++) ;
2,
++nc nc++
nc. .
,
int , long
long 32 .
, int long , int 16
, 327 67 ,
int.
%1d printf long.
double
(float ) . , while for
.
, , .
#include <stdio.h>
/*
main()
2-
*/
double nc ;
for (nc =
1.5
printf
%f
float
double; %.0f
21
, .
for ,
.
for . - ,
, .
.
,
,
while for
getchar , .
. while for
,
, ,
.
.
while for
.
1.5.3
.
,
,
. ,
.
jinelude <stdio.h>
/*
*/
main()
{
int
nl;
nl
;
while ((= getchar())
if ( =
'\n')
++nl;
printf( "%d\n", nl);
!= EOF)
while if ,
++nl. if ,
, ( )
.
22
. EQ.
=
. :
=.
2,
, ,
.
. ,
. , , ' '
; ASCII , 65
. , ' '
6 5:
, ,
,
'\n'
"\n"
.
2 .
1-8 .
(- , ).
1-9.
, , -
-.
1-10.
, ,
(.
backspace)
\t ,
\b \\ .
,
.
1.5.4 3
, , , ,
, ,
, , .
UNIX wc.
1.5
23
#inelude <stdio.h>
/*
/*
#define IN 1
#define OUT
/*
main ()
*/
*/
*/
,
.
state
; " " ,
u .
IN u
1, ,
. , ,
,
. ,
nl = nw = ne =
.
,
24
nl
1 1 ,
\t
. )
&& ; ( )
11
&&
11
. - ,
,
. ,
, .
, ,
else,
if .
()
if
else
1
2
if-
else . , 1 ;
, 2
else , if
1-11 .
,
?
1-12 . ,
1.6
,
, , )
1.6
25
,
.
:
1*
. , : ,
*1
main()
{
11
'\t')
%d\n",
diqits = 9 3
1, white
intndigit[10];
ndiqi t .
ndiqi t [] ,
ndigit[1], ... , ndiqit[9]. for
,
.
. ,
26
if
(>=
&&<=
'0'
'9')
. ,
-
'0'
'9'
.
. ,
, ,
,
ehar
int
; - ''
9, ,
ndigit.
, ,
if
==
'\t')
if
( )
else if
( )
else
.
. ,
~ ;
. (
)
, ( )
else. else ,
, .
1.7
else if
27
()
if
else.
; if
else ,
.
switch, 4 ,
,
. ,
switch 3 . 4 .
1-13.
.
;
.
1-14 .
1.7
,
, .
,
, .
,
; .
, ;
,
.
m, n .
, power (2 ,
5) 32. ,
,
( pow ( , ) )
power main ,
28
#include <stdio.h>
int power(int m, int n);
/*
main ()
power */
int i ;
for (i=O; i<lO; ++i)
printf ("%d %d %d\n", i, power (2, i) , power ( -3, i)) ;
return ;
/* power:
intpower(intbase, intn)
n ; n>=O*/
inti,p;
p=l;
for (i=l ; i<=n; ++i)
= *base;
returnp;
:
- - - ( , )
()
,
,
. ,
,
,
, . ,
,
na
n .
power main,
1.7
29
power
. ,
power (2 , i)
, 2
i. ( ;
4.)
power
power
power ,
:
. , ,
i
ma.in.
power
, l
1
.
power main
return. return :
return ;
;
return
, 1
. " " ,
.
.
return main .
main ,
. ,
;
return
main
, 1
intpower(intbase, intn);
30
main 1
int
npomomun
1 power.
int.
power
ANSI
.
1
power
/* power : n
/* ( -) */
power(base n)
int base 1 n ;
n ; n>=O* /
int i ,
= 1;
for (i = 1 ; i <= n ; ++i)
= * base ;
return ;
1
;
int.
( )
power
int power () ;
,
power . ,
int ,
power
.
ANSI
1.8
31
, ,
, .
1-15 .
1. 2, .
1.8 -
,
, . ,
" " .
,
. ,
" ",
var ,
, .
;
.
, .
,
. , power
:
/* power: n
int power(int base, int n)
int
for
n; n>=O ;
2 */
;
(
= 1; n > ; --n)
base;
= *
return
n ,
(n for ) ;
i.
power , power
.
,
.
(, ) ,
32
.
.
.
, .
. .
1.9
.
,
. :
while ( )
if
( )
. , ,
.
,
. ,
qetline .
.
,
qetline ;
. ,
. ;
,
1.
. , ,
. ,
main
getline . :
1.9
#include <stdio.h>
#define AXLINE 1000 /*
33
*/
*/
int len ;
/* */
int max ;
/* */
char line[AXLINE] ;
/ * */
char longest~] ;
/* .r .n 'r-* /
max = ;
while ((len = getline(line, AXLINE))
if (len > max) {
max = len ;
copy(longest , line);
if (max > ) /*
printf(" %s ", longest) ;
return ;
/ * getline:
int getline(char [] , int lim)
int
>)
*/
, * /
i;
for (i=O ; i < lim-1 && (c=getchar())!=EOF && c!=' \n'; ++i)
s[i] = ;
if (= '\n' )
s[i] = ;
++i ;
s[i] = ' \0 ';
return i ;
int i ;
i
= ;
34
getline
main
getline
getline ,
lim.
, .
, .
void ,
"hello\n"
,
, '\ ' .
printf
. ,
,
'\0 ',
. , main
?
getline
,
, .
,
main
.
.
1.1
35
,
,
(r.
overflow) .
getline ,
getline
( ) ,
1-16
,
, .
1-17
1-18
, , ,
.
1-19 reverse () .
1.1 w
; ,
i getline
i .
.
,
. ,
( 4 .
static ,
.)
, ,
. , .
.
,
(.
external) , . ,
. (
36
>N
)
,
, . ,
, . .
,
.
, ,
;
. , ,
;
. extern
, . ,
, ,
#include <stdio.h>
#define
AXLINE
1000
int max ;
char line[AXLINE];
char longest[AXLINE];
/*
*/
/*
/*
/*
*/
*/
* /
int getline(void);
void copy(void);
/ * .
main()
; */
int len ;
extern int max ;
extern char longest[] ;
max = ;
while ((len = getline())
if (len > max) {
max = len ;
() ;
>)
if (max > ) /*
printf("%s ", longest) ;
return ;
*/
1.1
/* getline :
int getline(void)
37
*/
int , i ;
extern ehar line[] ;
for (i = ; i < AXLINE - 1
(e=getehar)) != EOF
line[i] = ;
if ( '\n' ) {
line[i] = ;
++i;
"
"
!= '\n'; ++i)
line[i] = '\0';
return i;
/* :
void eopy(void)
*/
int i ;
extern ehar line[], longest[] ;
i = ;
while ((longest[i]
++i ;
line [ i] ) ! =
'\ '
main , getline
n n , n
n. ,
n,
n , .
, n
;
extern.
extern n.
, n
n n ~ , n n extern
.
extern main,
getline . , n n n
n n
.
n n , n
"l ", "2", " ",
38
extern
header),
#include
h
, ,
<stdio h>
4, 7
getline ,
, getline () ()
,
;
void o
4
,
""
; ""
,
extern , -
,
,
,
-
, ,
,
,
,
,
,
1-20 detab
-
- -,
n n ?
101
39
1-210 entab
detab
- ,
?
1-22
" "
, n-
1-23
1-24
, (
, )
( )
( ,
2: ,
33
, .
.
.
.
.
ANSI
. (.
signed) ( .
unsiged )
t- .
n ; ,
long double
. .
const,
, ,
2.1
1 ,
. ; .
"_ " ;
,
.
, .
,
.
31
. -
41
42
31,
(.
assemblers)
(.
loaders)
.
,
2.2 rn
:
char
int
,
,
float
double
, n
.
short long
""'
int ,
.
short long
; int
short
16 , int 16 32 .
short
int
long.
signed unsigned char
. unsigned
,
2n , n
. , , char
8- , unsigned char
2.3
255,
43
,
.
1ong doub1e .
,
;
float, doub1e,
1ong doub1e
, .
. .
2-1 . char, shor ,
int 1ong , , ,
. :
2.3
1 ()
L,
1234,
int . 1ong
123456789L;
int, , 1ong.
u
u,
( 1-2)
(123. 4)
; doub1e,
u1 UL
unsigned 1ong.
F float ; 1
1ong doub1e.
,
. ()
;
.
037,
31
Ox1f OxlF.
L, 1ong ,
15.
,
, ''
. ,
ASCII , ' '
48, .
'' 48, ,
44
n,
. n
n, n n
.
, n
\n
( )
, n . n,
n n
'\'
( 7)
'\xhh '
hh n ( .. 9 , .. f , . . F) .
n
"
()
\b
\f
\n
\r
(.
carriage
\\
\?
\'
\"
\xhh
return)
\t
\v
'\0' n ,
'\0'
, .
.
(.
null)
. , n
n ,
2.3
45
, , ,
#define LEAP 1 / * */
intdays[31+28+LEAP+31+30+31+30+31+31+30+31+30+31];
~ ,
:
"
sum string"
" " 1* n * 1
, ,
. ,
;
\"
(. tt) :
.
,
strlen ()
, ,
,
'\ '
46
/* strlen:
int strlen(char [])
int i;
while ( [i]
++i;
return i;
strlen
*/
!= '\0')
<string. h> .
: '' " " .
,
. , , ( )
'\0'.
. .
, , ,
enumboolean {NO,
};
, 1, ,
.
,
,
:
#define,
enum ,
. ,
#define
. , (.
debbuger)
2.4
47
2.4
,
.
int
int
int
char
c har
lower ;
upper ;
step ;
;
line[1000] ;
,
.
.
,
:
ehar
int
int
float
= ' \\ ' ;
= ;
limi t
=AXLINE + 1 ;
= 1 . -5 ;
,
,
, .
.
.
(.. ) .
const
.
.
const
48
const
const ,
2.5
+ ,
- , *, 1, %.
.
%
. , 400 ;
4,
100.
if
float
double .
%,
. (.
overflow
uderflow)
+ - ,
*, 1, %, , , + -.
.
2 . 1 ,
2.6
49
2.6 n nr
>
<
>=
<=
.
=-=-
! =
i < 1im-1
i < (1im-1) , .
1 1 &&
&&
11
. ,
get1ine
for
1:
&&
! = EOF ; ++i)
= ;
,
, , ,
i < 1im - 1 .
, ,
, , EOF ,
getehar;
&&
1 1,
i < 1im-1
&&
&&
!=EOF
. ,
! =
(e=getehar()) != '\n'
,
'\n'.
! ,
1.
50
if ( !valid)
i f (valid
== )
!valid
( " " ) ,
2-2.
for
, &&
2.7
1 1.
. ,
"
+ i. ,
float , .
,
,
int,
, , .
na
char
.
.
atoi,
/* atoi :
int atoi(char [])
*/
int i , n;
n
&&
1,
2.7
51
s[i]- '0'
[i] , ,
''
, '1' ,
ASCII, .
1ower .
/ * lower: /
int lower(int }
if
(>=
' '
return
return
&& <=
''
ASCII */
'Z'}
'' ;
, , ASCII ,
,
. , EBCDIC,
.
<ctype. h >, ,
,
. ,
>=
tolower
lower . ,
isdigit(c}
<ctype
. h>.
char int .
char , (.
siged) (. usigned) .
char
int,
, .
char 1
. , ,
(" "}
,
.
52
,
, .
, ,
,
. ()
signed
ehar ,
unsignedeapaja .
d = >=
<= '9'
. ,
isdigit "" .
. " " , ,
,
. , (
),
+ -,
, " "
unsigned ,
, <math . h>
.
fioat
, , ,
unsigned
.
,
. ,
int
2.7
53
, ,
n.
.
inti;
ehar ;
i = ;
c=i ;
.
.
float i int, , = i i =
float int . n
double floa t, ,
n ,
n .
cast) .
onepamop (.
( )
. n n
n ,
. n ,
sqrt
double, na
, n .
<math . h>.)
sqrt ( (double) n)
( sqrt
, n
54
doub1e
sqrt .
.
, .
, ,
. , sqrt
( .
seed); :
/ * rand :
int rand(void)
= 1;
.. 32767 */
/ * srand : n rand()* /
void srand(unsigned int seed)
{
n ext
= seed ;
2-3 . htoi () ,
( )
.
2.8 3
9, f,
F.
++
2.8
--
55
1 .
++ ,
if
(=
'\n')
++nl ;
n ++ --
n (n n , ,
++n) n
n++) . ,
n . ++n n
, n++ , n
n (n n:
.
,
++n n++
n 5,
x=n++ ;
n
x=++n;
n . ,
. n
(i+j) ++ .
,
,
if
(==
'\n')
nl++ ;
.
. n ,
squeeze ( , ) , n
:
1* squeeze :
[] ,
*1
int )
int i,
56
r ,
,
.
i f (s[i]
{
=s[i] ;
!=)
[]
++ ;
if
(=
qetline
1 .
'\n ' )
s[i]
++i ;
= ;
if
(=
'\n ' )
[i++] = ;
streat ( , t) ,
streat
strcat
/* strcat: ~ ro t JCP&jor
void streat(ehar [] , ehar t[])
; : 1010 01!
*/
int i ,
i = = ;
while (s[i] != '\0') /* */
i++ ;
while ((s[i++] = t[j++]) != '\0' ) /* n t */
, ++
, ,
2.9
2-4.
squeeze
57
(1 , 2)
1 2 .
2-5
. any ( 1, 2) ,
-1 1
2 . ( strpbrk ja
, . )
1, 2 ,
2.9
; , ,
. ,
&
<<
>>
(.
shift)
()
&
, ,
n =n
&
0177
7 n, .
1 :
1 SET_ON ;
1 ,
1 _ ON .
"'
, .
&
&&
1 1,
--.
2,
& , && .
<<>>
, . << 2
, ;
4.
unsigned
58
,. " )
( ,.
") .
- ; . .
1- - .
= &
- 077
. &
-077
, , , &
0177700 ,
16- .
- 077
getbi ts
( , ,
n)
( ) n-
getbi ts
( , 4 ,
3)
. ,
4 ,
3,
2,
1* getbi ts :
n */
uns ignedgetbits (unsignedx , intp , intn)
return
>> (p+1- n)
& - ( - <<
n);
n -
<< n n ;
, - n .
. - ;
2- 6 .
setbits
( , ,
n,
) n
n- ,
.
2- 7 . invert ( , , n) n
, 1
, ( . .
)
2 - 7.
rightroot
.
(,
n)
2.10
59
2.1
i=i+2
n n ,
n nn
i +=2
n +=
onepamop .
n (n +
n) n
on=, on
1 n .
:
*=+
(+
1)
=*+1
n n
bitcount ,
, n .
60
1* bitcount:
1-
*/
intb ;
for (b=O;
if
( &
!= ; >>=1)
01)
b++ ;
returnb ;
unsigned
, ,
, .
,
. ,
"
, , i ". i += 2 i =
+ 2.
, .
.
;
(+=, -=, . )
, .
,
, .
. .
bi tcount.
2011
2.11
61
n 33
if(a>b)
z=a;
else
z=b;
b ,
"?:"
2 : 3
()
, ,
3
2 3 ,
z b
z = ( >b) ? : b; /* z =max(a, b) */
2 3
, ,
float
n int,
(n>O) ?f: n
float,
?:
,
n- ,
10 ,
, ( )
' ');
62
, n- .
.
,
i f/ else.
2-10.
"" ) ;
l ower,
if-else.
2.12
2 . 1 ()
, .
;
, ,
* , 1 % ,
+ -. "" ()
. -> .
; , sizeof (
) . * ( ) & (
) , ',' ( ) .
2.1-
onepamopume
() []-> .
! - ++ -- + -
(type) sizeof
* 1%
+-
<<>>
<<= >>=
== !=
&
&&
11
?:
+ , -,
* .
2012
& ,
63
= ! =
i f ( ( & )
== 0)
, ,
( && ,
11 , ? :
' ,'
) ,
x=f() +g();
f g, ; , f
g ,
,
,
n power
++n ;
printf( "%d%d\n", n, power(2, n));
,
, " "
a[i]
= i++;
( )
,
printf, .)
, ,
. ,
,
,
.
3:
( ) ,
.
;
3.1
()
- ,
= ;
i++ ;
printf{ ... ) ;
, - ,
.
, ,
.
;
; 4. )
-
3.2 if-else
if - else
65
66
if(upo)
else
else . , ;
( . . , ) , 1
( )
else , 2
if, ,
, . ,
if (izraz)
if (izraz
!=)
; .
else
else ,
if .
else if else .
if (n>O)
if(a>b)
z
= ;
else
z =b ;
else
if ,
, :
if (n>O) {
if(a>b)
z=a ;
else
z =b ;
else- if
3.3
67
if (n>O)
for (i=O ; i<n; i++)
if ( [i] >) {
printf(" . .. " ) ;
return i;
/ **/
else
else if.
;
, ,
. , -
if
if
z =
>b)
= ;
else
z=b;
, if ,
,.z = ;" - .
3.3 else- if
if
()
else if
()
else/ff ()
else if
()
else
if
. ; ,
. ,
68
else
1 , ,
;
else
, ,
""
1
v v
( n- 1 )
v
-1
, , ,
v ,
,
1
1
<= v[n-1] */
*/
*/
v [mid] ;
else- if
switch
3.4
3-1.
69
, (
) .
.
3.4switch
swi tch
.
switch
( )
- :
-:
defaul t :
(. )
.
, .
. defaul t
. defaul t
;
, .
defaul t .
1 ,
, , if . . . else
if . . . else . , swi tch :
break swi tch .
(a. label),
, npeoza ,
. break return
swi tch . break , ,
while , for do ,
.
.
,
. , ,
break ,
.
.
,
, .
70
n5 ,
r* /
' 3 ':
'8 ':
' 4':
' 9' :
printf( "digits=" ) ;
for (i=O ; i<lO; i++)
printf( "%d" , ndigit[i]);
printf ( " , white = %d , other = %d\n",
nwhite , nother) ;
return ;
, break
( defaul t)
, .
switch,
3-2.
( , t)
\n
\ t,
...___
swi tch.
, , .
- while
3.5
for
71
while
()
, . ,
, , .
.
for (l; 2; )
upl ;
while
(u2 )
continue, 3 . 7.
, for . up l
, 2 .
, -
. upl , ,
2, ,
for ( ;; )
" " ,
, , break
return.
for while .
,
/
while
((
; /*
= getchar())
'
'
11
==
'\n'
11
n n
' \t ' )
*/
, while .
for
72
,
.
for .
, , ,
for
for
. ,
for ,
atoi
2;
-.
atof ,
.)
:
,
,
2 */
inti , n, sign ;
for (i
= ; isp&ce(s[i]) ;
i++) /*
r n */
(+/-)*/
3.5
- while
for
73
strtol
5
- sort
. ,
1959
. .
n .
,
.
,
.
*/
int qap , i,
temp ;
, ,
n/2
. , , n
nap nap
qap .
qap ,
. for
,
for
(',' ),
. , ,
. ,
for ,
, n, .
reverse () , .
74
#inelude <string.h>
/* reverse: */
void reverse(ehar [])
{
int
i,
for (i =
s[i] =
[]
= strlen(s)-1; i <
i++,
--)
[i] ;
[];
=;
,
, .
.
, for
reverse
.
reverse,
3-3.
--)
expand (1 , 2)
xyz 2.
b- - zO - 9
z . - .
--
\
. n
do- while
1, while for
. ,
, do- while, ,
;
do
do
while
()
3.6
Do- while
75
, .
, , , , .
, . ,
/* itoa: n
void itoa(int n, char [])
*/
int i, sign;
if ((sign =n) <) /* (+/-)
*/
n = -n;
/* n n */
i = ;
do {
/* */
s[i++] =n % 10 + '0';
/* */
} while ((n/= 10) >);
/* */
i f (sign < )
[i++] = '-, ;
s[i] = '\0';
reverse(s) ;
do - while , ,
, n
. ,
, ,
while while .
3-4 .
i toa , n
- (2n__- 1 ) .
, .
, i
b, .
76
3-6 .
itoa , , n
. .
n
n n
. ( . n .
n n .
break n
for , while do , swi tch. break n
swi tch .
, trim, ,
, break n
n
, ,
- " " .
/ * trim:
int trim(char
*/
[])
int n ;
for (n= strlen(s)-1 ; n>=
if (s[n] != ' ' && s[n]
break ;
[n+l] = '\0';
return n ;
n- -)
!= '\t '
&&
s[n]
!= '\n ')
strlen . for
. n n n
n . ( , )
n .
continue
break,
n ;
n n n
n .
goto
3.8
77
,
; .
continue
*/
n,
3.8 goto
goto
goto
goto.
goto .
.
break,
. :
for ( ... )
for ( ... )
if (disaster)
gotoerror ;
}
error :
/*
~ ~
*/
goto . ( . )
,
b .
78
*/
a[i] -- b[j] * /
goto 1
. 1 1
:
found = ;
for (i = ; i < n && !found; i++)
for ( = 0 ; < m && !found; ++)
if (a[i] == b[j])
found = 1 ;
if (found)
/* : a[i-1]
b[j-1] * /
1
/*
*/
1 1
goto 1
goto .
1 , goto
, .
4:
, .
,
.
; ,
. .
,
. .
, .
ANSI
1,
. , ,
, .
. , ,
.
. :
.
t, , .
, .
4.1
, "" . (
79
80
grep UNIX) . ,
"ould"
while (n )
if ( )
<.
main ,
n.
,
,
. .
" n ",
getline ,
strindex ( , t)
t , - 1
t.
, -1 ,
.
n ,
strindex ,
strstr
strindex ,
).
. ,
. , ,
n .
,
-
401
- ,
81
qetline ;
~ n
~ ~
*/
*/
char line[AXLINE]
int found = ;
return found ;
/* qetline:
int getline(char
int
,
[],
*/
int lim)
i ;
! = '\n ' )
*/
82
/* strindex: t
int strindex(char [] , char t[])
int i ,
-1
*/
k;
[j]=t[k];
++ ,
k++)
- - - ( )
dummy() {}
.
, .
- ,
int .
.
,
, .
,
,
.
return
. return :
return ;
,
. ,
.
. , return , ;
, .
4.2
83
"
"
.
, , , ,
. , , "
" .
main ,
.
,
, .
UNIX,
, ,
. ,
getline. strindex .
*. ,
. out. , ,
main. ,
4.2
( void) int.
? , , sqrt, sin
double ; .
,
atof () ,
atof
atoi 2 .
,
.
84
,
.
atof
<ma th. h>.
, atof
, .
~n
double * /
= ;
isspace(s[i]) ; i++) / *
:r n * /
power ;
iinc1ude <stdio.h>
idefine
AXLINE
/ * ~
main ()
100
~
*/
4.2
, , ,
85
atof
in t. ,
atof
( ).
, , ,
char [] ,
double .
tof
. atof
main ,
. , ( )
, atof
, , tof double ,
main int ,
.
, .
,
,
int,
. ,
double tof () ;
atof; n .
n
. n
. ,
, void .
, atof n ,
atoi ( int) atof :
86
1* atoi:
atof */
[])
[]) ;
return.
return ;
, .
,
atof , double ,
return , int, atoi
int. ,
.
(. wa ring).
4- 2.
atof ,
123. 45-,
.
4.3
,
. ""
"",
.
, .
,
.
, ,
. ( .)
, N
.
,
, -
4.3
87
.
, .
, ,
. ,
1, ,
,
.
.
;
. , , ,
. ,
, ,
, .
.
+, -,
* 1.
()
,
.
,
;
(1-2) * (4+5)
12-45+*
;
.
. , ( .
stack);
, , . ,
1 2
-1 . ,
4 5, 9 .
,
-1 9
, -9.
. ,
11
, .
88
__)
while (
i f ( )
els e if
( )
else if ( )
else
n ,
,
,
na
, n ,
n n. , n
n n.
, n , n
nn .
main,
, n .
, 1114in n
; n
main
, n. ,
n n
push , main .
- .
n ,
:
#include -ou,
#define -o u,
main
1114in () { . . . )
push
voidpush ( double f) { . .. }
double (void) { . . . }
intgetop(chars[] ) { . . . }
getop
4.3
#include <stdio.h>
#include <stdlib.h>
89
/* for atof() */
n */
int type;
double 2;
char [];
while ((type = getop(s))
switch (type) {
!= EOF)
NUER:
push(atof(s));
break;
' +' :
push(pop() + ());
break;
'*':
push(pop() * ());
break;
'-':
2 = () ;
push(pop() - 2) ;
break ;
'/':
2 = () ;
i f ( 2 !
. )
push(pop() 1 2);
else
printf("error: zero divisor\n" );
break;
'\n ':
printf("\t%. 8g\n", ()) ;
break;
default:
printf("error: unknown counand %s\n",
break;
return
) ;
90
. ID4in
swi tch
swi tch 1 . 4.
* ,
push(pop() -
());
/**/
. ,
#define
AXVAL
int
double
val[AXVAL] ;
= ;
main.
100 /*
/*
n n
/* push : f
void push(double f)
/*
val */
*/
*/
xyn */
if
<
AXVAL)
val[sp++]
f;
else
printf("error: stack full, can 1 t push %g\n" , f);
/* :
double pop(void)
*/
if
>
return val[--sp] ;
else {
printf( " error: stack empty\n" ) ;
return 0.0;
. , n ,
push , . ,
main -
.
getop, . .
. . --
4.3
91
. ,
. , {
, NUER, .
while { { []
= geteh {) ) -
s[l] = '\0' ;
if {!isdigit{e) &&
return ;
i
*/
[])
'
'
11
'\t l )
!= '. ' )
/* */
= ;
if {isdigit(e))
/*
while {isdigit{s[++i] == geteh{)))
if
(==
' .1 )
/*
while {isdigit{s[++i] == geteh{)))
*/
* /
s[i] = '\0';
if { != EOF)
ungeteh(e);
return NUER;
geteh ungeteh?
,
.
: ,
. ,
,
"
" . , 1
1
. 1 ""
1 .
;
geteh
ungeteh ,
getch .
.
ungeteh
geteh
92
, getchar . ,
.
getch ungetch
, . ,
getch , ungeteh
void ungetch(int
/*
( )
? buf[--bufp]
ro
buf */
*/
: getehar() ;
*/
ungetc
; 7. ,
, .
4-3.
. (%) .
4-4.
,
.
pow.
4-5 .
sin , ,
4-6.
<math . h>
4.
. (
26 .)
.
4-7 . ungets ()
. ungets buf bufp , , ,
ungetch?
(. )
4.4
4-8.
4-9.
getch
getch
ungetc h
ungetch
EOF .
93
4-10.
EOF
getline
; getch ungetch .
.
4.4 (. }
,
, ;
,
.
:
, ,
- ?
. ,
,
.
,
.
, .
.
,
.
, .
94
main () { ...
int = ;
double val [AXVAL] ;
void push (double f) {
double (void) { ... }
val
push
, ,
; .
main, push.
,
, , , ,
extern.
(, )
int ;
double val [AXVAL] ;
,
val, , . ,
. ,
extern int ;
extern double val [] ;
int , val
double
( )
, .
,
;
extern
. (
extern
extern
, push
, val
( . )
4.4
95
.
:
1:
extern int ;
extern double val [] ;
voidpush (double f) {
double (void) { ... }
2:
intsp= ;
double val
[AXVAL]
extern l
, ;
l .
val
4.5 3
,
.
main ,
main . ; push , ,
staek. ; gettop , gettop . . , geteh ungeteh
geteh . ;
96
calc.h:
#define NUER ' '
voidpush (double) ;
double (void) ;
intgetop(char []) ;
int getch (void) ;
void ungetch (int) ;
main.c:
getop . c:
100
main() {
stack . c:
#include <stdio. h>
#include " calc . h "
#define AXVAL 100
intsp=O;
double val [AXVAL] ;
voidpush(double) {
getch . c:
#include<stdio.h>
#define BUFSIZE 100
char buf [BUFSIZE] ;
intbufp=O ;
int getch (void) {
double (void) {
-
.
,
,
. ,
() calc. h ,
. ( #include
4 . 11) . :
,
.
, , ,
;
. ,
.
4.6
4.6
97
val
staek . ,
statie,
,
. ,
statie .
, :
{... }
, buf
bufp
. ,
push ,
val .
statie , , ,
, , . ,
, .
,
.
.
,
,
.
,
.
4-11. getop,
ungeteh. : statie .
98
4.7
register
.
,
. , .
:
register int ;
register char ;
.
:
register int i;
.
,
. ,
register
. ,
( 5) , ,
, .
.
4.8 n
. ,
.
( )
,
.
.
4.8
if ( n
>
99
) {
int i;
/*
for (i
= ;
i* /
i < n; i++)
i if
; i i .
,
static
.
, ,
, .
,
intx;
inty;
f(doublex)
{
doubley;
f,
double, f,
int. .
4.9
,
. ,
.
(. . )
.
,
:
100
intx=1;
char squote = '\' ' ;
long day = lOOOL * L *
*24L ;
/* /*/
,
; ,
. ,
.
,
;
, . ,
3 . 3
intlow=O;
int hight =n - 1 ;
intmid;
. , , ,
.
. ,
days
12 .
4.10
101
,
, .
.
, , ,
.
;
:
char pattern []
=" ould";
charpattern[]
= { ' ',
, {
'\0').
4.1
; ,
.
. ,
:
,
.
.
,
, itoa .
6.
, printd
, .
, .
/* printd : n
void printd(int n)
i f (n
< 0) {
1 10)
printd(n 1 10) ;
putchar(n % 10 + ' 0 ' ) ;
if (n
*/
102
,
,
, . printd (123)
printd n=123. 12 printd, , ,
1 . printd 1 ,
. printd 2,
. printd 3
.
quicksort ,
. . .
1962 . ,
, .
,
; .
quicksort , ,
.
.
*/
int i, last ;
void swap(int v[] , int i , int
if (left >= right) /*
) ;
*/
return;
swap(v, left,
(left + right)/2) ; /* n
v[O] */
last = left ;
for (i = left + 1 ; i <= right ; i++) /* n */
if (v[i] < v[left])
swap(v , ++last, i);
swap(v , left, last) ; /*
n
*/
swap ,
qsort .
4.11
103
int temp ;
temp
v[i]
v[j]
v [i] ;
v[j] ;
temp ;
qsort,
n.
,
. , n, . ,
n
.
, ,
. .
4-12.
printd ,
i toa ;
.
4-13 . reverse ()
4.11
#include ,
#define
.
.
4.11.1
(
)
#define
104
< >,
n .
#include .
#include n
#define extern ,
nn nn
, , n,
<stdio.h>. ( , ;
nn n) .
#include
.
,
. ,
, n.
4.11.2
#define
n -
__. #define
.
n ,
, n
.
#define n
. n
.
, n,
n
N.
. n:
*/
4.11
, forever,
105
. ,
max:
#definemax(A , ) (()> ()? () : ())
, max in-
line ( ) .
( ) .
x=max(p+q, r+s) ;
,
;
max ,
.
max , .
;
, . :
max(i++, ++)
/*
*/
,
;
#define square(x)
/*
*/
square ( z + 1) .
, .
<stdio. h>, getchar putchar
. <ctype. h>, ,
.
#undef
, , , , ,
, :
106
#undef qetchar
int qetchar (void) { ... }
(
). , #
,
.
, ,
.
= %q\n", expr)
dprint (/)
/) ;
/) ;
, " \" \ \\ ,
.
##
.
,
##
##,
. , paste
:
paste (name, 1)
namel.
## ;
.
t. ( ) .
4 .11
107
4.11.3 n n
.
,
iif (
sizeof , enum ).
, #endif #elif #else
.
#if !defined(DR)
#define DR
/*
hdr.h
*/
#endif
hdr. h DR ;
n
#endif .
n . ,
,
.
:
#if
==
SYSV
#define DR "sysv. h "
#elif = BSD
#define DR " bsd.h"
#elif = D
#define DR " msdos . h "
#else
#define DR " default . h "
#endif
#include HDR
\08
ftifdef
iifndef
ftif
ftifndefDR
ldefineDR
/*
iendif
hdr . h
*/
5:
; ,
goto
, ,
ANSI
, vid* (
void)
char*
5.1
char , short
long
( ) ,
char ,
109
110
& ,
= & ;
"
" . & :
. , ,
register
onepamop onepamop
; ,
.
, ip int.
&
int
1,
int *ip ;
=2,
= &;
= *ip;
*ip
ip
/* ip n
/ * 1 */
/* */
/* ip n
ip
z[10] ;
/* ip
= ;
= &z[O] ;
*:
int * /
*/
z[O] */
, , z .
ip ,
int* ;
;
*ip
int
,
.
. ,
doub1e*dp , atof(char*) ;
atof
*dp
atof ()
char.
double
,
:
. ( : "
void"
.
5.11)
ip , * ip
,
5.2
111
*ip=*ip+10 ;
*ip
10 .
& ,
y=*ip+1
ip,
1 ,
*ip += 1
ip ,
++*ip
(*ip)++
; ,
ip,
* ++
, ,
. , iqe int ,
iq= ip ;
ip iq, iq
ip.
5.2
, ,
. ,
swap . ,
swap(a, b) ;
swap
112
void swap(int
int
/*
*/
int temp ;
= ;
temp
= temp;
, swap b
.
b.
, -
:
& , &
swap
voidswap(int*px , int*py) / *
{
int"temp;
temp=
* ;
*= *;
*=
temp;
:
:
b :
* *
*/
5.2
113
n
.
getint, ,
, ,
. getint
.
, ,
EOF,
,
.
scanf ; n 7 . 4 .
getint:
intn, array[SIZE], getint(int *) ;
for (n=
array [n]
n .
array[n] getint .
getint .
getint EOF ,
, , ,
.
*pn
*/
int , sign ;
while (isspace (= getch ())) / * n
if (!isdigit(e) && '=EOF&&c !='+ '
ungetch () ; 1* */
return ;
nu
&&!='-')
*/
114
, ,
.
5-l .
getint
, .
5-2.
getfloat ,
getint ,
getfloat?
5.3
, ,
.
,
.
, .
inta[10] ;
10 , 10
[], [1] ,
... , [9] .
:
[][1]
[9]
[i] i- .
'\
.....
503
115
int *;
= &[];
; ,
[]
:
[]
= *;
[]
,
+1 ,
+i
i- ,
- i i- , [],
a[i]
[1],
+i
[i],
(pa+i)
(+1)
[]
,
"
"
, +1
, pa+i i-
,
,
116
=& [] ;
.
,
&
[i]
= ;
[i]
* (a+i) . [i] ,
* (a+i) ; .
&
[i]
& ,
a+i , , : a+i i -
. , ,
;
pa[i]
(pa+i) .
(. offset).
. , , = ++
. ; = ++ .
,
, .
, ,
, , .
strlen,
/* strlen :
int strlen(char *)
*/
int n ;
for (n = ;
n++ ;
return n ;
!= ' \0 ',
++)
, ;
++
strlen,
strlen .
/* string */
/* char array[lOO] ; */
/* char *ptr ; */
5.3
11 7
char
char
*;
[] ;
;
.
1 .
1 .
. 1
f(&a[2])
f(a+2)
f
[ 2] . f
f(intarr[]) { ... }
l .
1
; [-1]
[ -2)
[]
. 1
.
5.4
, ++
1
p+=i
i -
. -
11 8
.
;
, .
. . ,
alloc (n) ,
alloc . , afree () ,
,
alloc
( .
afree ,
stack)
8 . 7 .
alloc
allocbuf .
alloc afree . , ,
static
alloc afree ,
. ,
; malloc
.
allocbuf
alloc
allocp : "'-...
:L.. -1--L---LI---'-1----'-1--~--_____.
-+----+--
posle alloc
allocbuf
:1
------'~
-.
allocp :
11
"'-...
~~==~==~~~~~~~~~::::::~~;.:::~~~~~~-=~~
allocbuf .
allocp ,
. alloc n ,
allocp (. .
allocbuf.
alloc
, ) ,
, .
, alloc .
afree
()
allocp
allocbuf .
119
5.4
#define ALLOCSIZE 10000 / *
: n n
*/
alloc */
*/
n~ ~
* /
. n
*) /* n ~ n~
*/
*/
if
>= allocbuf
allocp=p;
&&
,
,
n*/
, allocp
allocbuf.
, alloc (
)
, alloc
120
,
.
.
:
, NULL,
. NULL
<stdio . h>. NULL .
n*/
if
>= allocbuf
&&
. ,
. q
, =,
! =, <, >=,
. ,
p<q
, ,
q.
.
.
( :
,
.
p+n
n- .
,
.
int ,
int-o
, , :
< q,
q
q-p+l
q .
strlen :
5.4
/* strlen:
int strlen (char *)
121
*/
char *= ;
while (* != '\0')
++;
returnp-
, , . ,
. while ,
'\0'
. ,
++ ,
, . . , . (
int. <stdd.ef. h>
ptrdiff_ t
.
size_ t
strlen, .
size_ t sizeof . )
float,
float,
char
++
flo a t
alloc ,
, , ,
char float alloc
afree.
.
,
. .
, , ,
. floa t
double , , , ( void*)
5.5
,
"
sum string"
'\; .
122
.
,
printf
. ,
.
.
pmessaqe
char *pmessaqe ;
pmessaqe .
; .
.
:
'\ 0' .
amessaqe
, pmessaqe ,
,
.
;
,
.
pmessaqe:
~~--~-~lnow
amessage:
is the t ime\0
,
.
strcpy ( , t) , t
. = t,
5.5
123
,
,
. ,
. :
/* strcpy: t ;
void strcpy(char * , char *t)
*/
int i ;
i
= ;
strcpy
/* strcpy : n ro t ;
void strcpy(char *, char *t)
*/
while ( (*
++ ;
t++ ;
strcpy
t .
, , ,
'\ '
t, .
strcpy
/* strcpy : n ro t ,
void strcpy(char *, char *t)
2 */
t .
*t++
++
t,
t . ,
. ' \'
. t ,
' \0' .
124
, '\' ,
.
, , ,
/* strcpy: t ;
void strcpy(char * , char *t)
*/
while
(*++
= *t++)
,
,
.
(<string. h>)
strcpy
strcmp
(,
t) ,
t .
s==t, >0
s>t */
s==t, >0
s>t */
int i ;
for (i = ; s[i] == t[i]; i++)
i f ( [i] = '\0')
return ;
return s[i] - t[i] ;
== *t ; ++ , t++)
= '\0 ' )
return ;
return * - *t ;
*
(*
++ -- ,
*, , ++ --,
, . ,
5.6
125
*--
*++
val
= val ;
= *-- ;
/*
/*
val
*/
n
(.
;
val * /
push)
(. )
4 . 3.
<string . h>
5-3. strcat
2: strcat ( , t)
5-4. strend ( , t) , 1 t
, .
5-5 .
:
. ,
5-6 .
.
(
(
5.6
(
(
2, 3
getline
4), reverse
4) .
sort UNIX.
Shell sort)
1 - (.
1 4
quicksort . ,
126
,
, ,
.
.
. ,
, ---
,
.
strcmp .
, ,
.
. :
,
, main
.
.
. ,
,
.
,
r .
,
.
5.6
127
#include <stdio.h>
#include <string.h>
#define
char
AXLINES
5000 /*
*1ineptr[AXLINES] ;
/*
.* 1
*/
*/
int nlines ; / *
n */
NULL)
*/
128
/* writelines: n */
void writelines(char *lineptr[], int nlines)
{
int i;
for (i = ; i < nlines ; i++)
printf( " %s\n" , lineptr[i]) ;
getline
lineptr :
char *lineptr [AXLINES]
1 . 9.
lineptr
AXLINES ,
*lineptr [i]
char .
lineptr [i]
, . ., i-
lineptr
, ,
wri telines
/* writelines : n */
void writelines(char *lineptr[] , int nlines)
{
*lineptr ;
nlines .
Quicksort
strcmp .
, .
*/
int i , last ;
void swap{char *v[], int i , int
) ;
5.7
129
*/
return;
swap(v 1 left 1 (left + right)/2);
last = left;
for (i = left+1; i <= right; i++)
if (strcmp(v[i] v[left]) <)
swap(v 1 ++last 1 i) ;
swap(v left last);
qsort(v 1 left 1 last-1);
qsort(v 1 last+1 1 right);
1
swap
1* swap: v [i] v [] */
void swap (char *v [] int i int )
1
char *temp;
temp=v[i];
v[i] =v[j];
v[j] =temp;
~ v (. .
temp
lineptr)
char
1 ~
5-7.
readlines
alloc
main
. ?
5.7 ~3
~ 1
.
, 1
. 1 1- 60-r
, 61- .
:
,
day_of_year
month_ day
~ ,
, ~
. ~
1 ~ :
&m 1
&d)
130
m 2 d 29
(29- )
( "
" )
,
,
:
staticchardaytab[2] [13] = {
{0, 31, 28, 31, 30, 31, 30 , 31 , 31, 30 , 31 , 30, 31} '
{0 , 31, 29, 31 , 30 , 31 , 30, 31 , 31, 30, 31 , 30, 31}
};
/* day_of_year: :
int day_of_year(int year, int month , int day)
*/
int i , leap ;
leap = year%4 == && year%100 !=
for (i = 1 ; i < month; i++)
day += daytab[leap] [i];
return day;
1 1 year%400
/* month_day: , */
voidmonth_day(intyear , intyearday , int *pmonth , int *pday)
{
int i, leap;
leap = year%4 == && year%100 ! = 11 year%400 = ;
for (i = 1; yearday > daytab[leap] [i] ; i++)
yearday -= daytab [ leap] [ i] ;
*pmonth=i ;
*pday = yearday;
,
,
daytab daytab
day_of_year month_ day ,
char
char
leap ,
() ()
5.7
131
daytab .
1
, , .
daytab[i] [] /* [] [] */
daytab[i,j] /* */
,
.
, , ,
.
. daytab
,
1 12,
11.
, ,
.
, ;
, , ,
, 13 int .
, 13
int . , daytab
f, f :
f(intdaytab[2] [13]) { ... }
,
*.
int *daytab[13]
132
13 . ,
() ;
.
.12
5-8.
(day_of_year
month_day)
. .
5.8 n3
month_name (n),
n-
.
name
static . month_
.
.
/* month_name:
char *month_name(int n)
n-
*/
" " ,
"&rch" ,
"June " ,
name [n] ;
name, ,
lineptr .
; .
i- ,
name [i] .
name
5.9
5.9
3 3
133
name
[4]
b[]
[4]
. :
200
int
int-
b 20
int , 10
. ,
. ,
2 ,
20 ;
name:
illegal month\0
Jan\0
Feb\0
r\0
,
, t
month_ name.
char *name[]
= { "Illegalmonth",
charname[] [15]
={
"r "
};
134
aname :
1~llegil mont\O
Jan\0
r\0
Feb\0
15
45
30
5.1 r
,
, .
main ,
arqc ,
. (
arqument count) ,
(argv , arqument vector) ,
, ,
.
.
echo ,
. ,
hello , world
,
arqv[O]
1,
argc 1 .
argc
argc , arqv [ ] ,
ce" echo", " hello", "wrld" .
argv[l] , argv[argc-1] ;
, argv[argc] NULL .
. ,
argv[l],
argv[2]
5.10
echo argv
135
1 -
*/
int i ;
for (i = 1 ; i < argc ; i++)
printf ( "% % ", argv[i ],
printf( " \n " ) ;
return ;
(i
< argc-1 )
"") ;
argv ,
, .
argv, char ,
argc :
#include <stdio . h>
/* echo r
main(int argc , char *argv[])
2-
*/
(argc > 1) ?
"" ) ;
argv ,
argv[1]
argv[O].
(++argv)
*argv
, argc ; ,
. , printf
"% "
"% ",
*++argv) ;
printf , ,
. ,
, 4 . 1 . ,
,
. UNIX -o a a
grep, ,
, .
136
linclude <stdio.h>
linclude <string . h>
ldefine AXLINE 1000
int getline(char *line , int max);
/* find :
*1
char line[AXLINE) ;
int found = ;
if (argc != 2)
printf( " Usage : find pattern\n" );
else
while (getline(line, AXLINE) >)
if (strstr(line , argv[l)) != NULL)
printf( "% s " , line);
found++ ;
return found;
strstr ( , t)
t , NULL
.
<string. h> .
. .
"
"; "
".
UNIX ,
flag)
, (.
. - ( " ")
- n ("" ) ,
find
-n pattern
.
,
. ,
,
5.10
137
~ 1-
*/
{
eharline[AXLINE];
long lineno = ;
int 1 exeept = 1 number = 1 found = ;
while (--arge > && (*++argv)
while (= *++argv [])
switeh () {
[]=
'-
' ':
exeept= 1 ;
break ;
' n ' :
number= 1 ;
break ;
default :
printf ("find: illega1 option %e\n" ,
arge = ;
found= -1 ;
break;
) ;
if (argc != 1)
printf (" Usage : find - - n pattern\ n " ) ;
else
while (getline(line , AXLINE) >0) {
lineno++ ;
if ( (strstr (line 1 *argv) ! =NULL) != except) {
if (number)
printf( " %ld: " 1 lineno) ;
printf( " %s ", line) ;
found++;
return found ;
argc
argv
. , ,
argc
, argv -
138
argc 1 , *argv
*++argv ,
na ( *++argv) [] n . (
* *++argv.) [] * ++ ,
; n *++ (argv [] ) . ,
.
n ,
" " . ,
*++argv[O]
argv[O]!
n ; ,
n .
5-10. expr,
, n n
. n,
expr234+ *
(3+4 ) .
entab - m +n
- ,
m.
( ) .
5-13 . tail , n
n , , 10,
. n ,
tail -n
n .
n.
- 5 . 6, /
5.11
5.11
139
, ,
, ,
, ,
, .
,
,
-n,
, .
,
,
.
.
, ,
strcmp; , nncmp ,
,
strcmp. main ,
qsort.
, .
#include <stdio. h>
#include <string. h>
#define
AXLINES
5000 /*
char*lineptr[AXLINES] ;/*n * /
1*
{
intnlines ;/ *poj n
int numeric =; 1* 1 */
if (argc>l&&strcmp(argv[l] , " -n" )
numeric= 1 ;
==)
*1
*/
140
qsort, strcmp
numcmp
, & ,
.
qsort
, .
,
qsort
void*
void *
void*
qsort
.
,
*/
int i, 1ast;
void swap(void *v[], int , int) ;
if (left >= right) /*~ t11ro iDD _ . , _ 88 n::I81IICY Q N 81111 */
return;
swap(v , left, (left + right)/2);
last = left;
for (i = left+1 ; i <= right ; i++)
i f ( (*comp) (v[i], v[left]) < )
swap(v, ++last, i);
swap(v, left, last);
qsort(v , left, last-1, comp) ;
qsort(v , last+1 , right , comp) ;
qsort
5.11
141
comp void*
int. comp
<)
comp , *comp
int *comp(void *
void *) /*
*/
comp int ,
strcmp,
. nwncp ,
, atof :
.
sl
*/
double vl , v2 ;
vl = atof (sl) ;
v2 = atof (2) ;
if (vl < v2)
return -1;
else if (vl > v2)
return 1;
else
return ;
swap , ,
void * .
142
;)
void *temp;
temp=v[i] ;
v[i] =v[j];
v[j] = temp ;
; ,
5-14.
-r ,
()
-r - n.
5-15 . - f
; , .
5-16.
-d
( " " ),
, .
-f.
5-17 . ,
. ( -df
5.12
- n )
n n
,
.
;
, ,
,
int *f () ; 1* f :
: .
int */
int */
5.12
() ,
143
, ,
, ,
, .
typedef ,
6. 7 .
. .
,
dcl,
char **arqv
arqv : char
int (*daytab) [13]
daytab: [ 13] int
int *daytab[13]
daytab: [13] int
void *comp ()
comp : void
void (*comp) ()
comp: void
char (* (*()) [ )) ()
: []
char
char (* (*[3]) ()) [5]
: [3)
[5] char
dcl
dcl:
direct-dcl:
8 .5;
* direct-dcl
name
(dc/)
direct-dcl()
direct-dcl{onuca ]
,
* .
dcl ,
direct-dcl , direct-dcl
Direct- dcl ,
, ,
.
,
144
(*pfa[]) ()
pta
()
name
dir-dcl
1
dir-dcl
1
dcl
1
dir-dcl
1
dir-dcl
1
dcl
pfa direct-dcl . pfa [ ,
, direct-dcl. ooa, *pfa [] dcl, (*pfa [])
direct-dcl. , (*pfa []) () direct-dcl, dcl.
( direct-dcl
dir-dc[) :
dcl , dcl dir- dcl ,
.
, ,
, ;
.
1* dcl:
n */
int ns ;
for (ns=O ; qettoken() = ' * '; ) / *count*'s*/
ns++ ;
dirdcl() ;
while (ns-- >)
strcat(out , " pointer to " ) ;
/ * dirdcl :
*/
5012
145
int type;
if (tokentype=' ( ') { / * ( dcl ) */
dcl ();
if(tokentype!= ' ) ' )
printf ("error : missing) \n");
else if(tokentype==NAE)
1* nI */
strcpy (name, token) ;
else
printf( " error : expectednameor (dcl)\n") ;
while((type=gettoken())==PARENSI ltype==BRACETS)
if (type==PARENS}
strcat(out, "functionreturning" ) ;
else{
strcat(out ,"array") ;
strcat(out, token} ;
strcat(out , "of" );
,
, dcl o
char
int ,
, const
,
main
#include <stdiooh>
#include <string oh>
#include <ctype oh>
#define
enum
N,
100
PARENS ,
int gettoken(void) ;
};
146
int tokentype ;
/* */
char token[AXTOEN];
/* */
char name[AXTOEN] ;
/ * */
char datatype[AXOEN] ; / * data type = char , int , . */
char out[lOOO];
/* */
main()
/* * /
{
while (gettoken()
!= EOF) { /*
*/
strcpy(datatype , token) ;
out[O] = '\0';
dcl() ; /* * /
if (tokentype != '\n')
printf( " syntax error\n" ) ;
printf( "%s : % %s\n", name , out, datatype) ;
return
gettoken ,
nap
; " " ,
,
nap
int gettoken(void) /*
= ' (' ;
*/
5.12
for
(*++ = ;
147
*++ =;
*= '\0';
ungeteh(e) ;
return tokentype = N ;
} else
return tokentype =;
geteh ungeteh
4 .
,
.
undel
"
ehar" ,
x()*[]*()ehar
ehar ( * ( * () ) []) ()
gettoken . undel
/* undel : n */
main()
{
int type ;
ehar temp [N] ;
while (gettoken () ! = EOF)
strcpy(out, toke n) ;
while (( type = gettoken () ) ! = '\n ' )
if (type == PARENS 11 type = R)
streat(out , token) ;
elseif (type= '*') {
sprintf (temp, " ( * % ) ", out) ;
strepy(out , temp) ;
} elseif (type=NAE) {
sprintf(temp , " % % " , token, out) ;
strepy(out , temp) ;
} else
printf ( " invalid input at %s\n", token);
return
del .
148
5-18 .
5-19.
dcl
undcl
5-20.
dcl
const .
6:
,
. ( , ,
""
(. record) . )
, ,
, .
:
, ,
, .
: , ,
. , , :
, , ,
.
ANSI
,
.
, . ,
.
6.1
.
,
.
(4,3)
(0,0)
149
\50
structpoint {
intx ;
inty ;
};
struct ,
, . ,
( , ,
structure tag)
struct ( point ) .
,
.
.
( ) ,
, . ,
,
.
struct
, ,
. ,
struct { ... }
, ,
z;
intx,
z;
;
. ,
,
. ,
point,
structpointpt;
pt
struct point.
,
, :
6.1
151
, ,
n n.
n n n
__ . __
n "
" n
. , n
pt,
n :
0):
* pt. );
. n
,
nap
pt2
ptl
--~~----------------~
struct rect {
struct point ptl;
struct point pt2 ;
};
rect point .
screen
152
ptl 1
screen. ptl .
screen.
1 n
6.2
n n , n
n n
& nn . n
n
. n .
; .
n n
n. nn : n
n n
n n . n .
makepoint 1 n l
point :
/* makepoint:
struct point makepoint(int
int
*/
n
; 1 n
n .
makepoint
, n, n
:
6.2
153
.
,
/* addpoints: */
struct addpoint (struct point pl, struct point 2)
{
pl.x +=2 . ;
pl . += 2 . ;
returnpl ;
, ,
.
pl
ptinrect,
,
.
1* ptinrect:
&Jto
int ptinrect(struct point
return
&&
.
.
r ,
struct rect r)
nn
,
.
.
CIIpO'l'JIHO
*1
< r.pt2.x
< r.pt2 . y ;
ptl
pt2 .
() :
ldefine min(a, b)
ldefine max(a, b)
/* canonrect:
ur
(()
< (b) ?
()
(()
> (b) ?
()
(b))
(b))
*1
r . pt2.x) ;
r.pt2.y) ;
r.pt2 . x);
r.pt2.y);
154
,
,
.
structpoint * ;
point ,
struct point.
* , (*) . (*) .
. , ,
,
structpoint origin ,
* ;
= &origin ;
printf( "originis (%d ,%d) \n",
(*) ., (*) . ) ;
(*).
* .
. *.
* (. ) ,
. ,
- > __
. ( -+:
>). ,
->
-> , ->) ;
r.ptl.x
rp->ptl.x
(r .ptl) .
(rp->ptl) .
()
[] ,
-> ,
. ,
6.3
155
struct {
int len ;
char *str ;
} * ;
++p->len
len,
++(-> l).
(++) ->len , len,
->len len. (
. )
, *p->str str ;
*p->str++ str
str ( *++) ; (*p->str) ++
str ; *p++->str ,
str .
:
(++)
6.3
.
.
,
keyword keycount ,
char *keyword[NEYS];
int keycount[NEYS];
, ,
. :
char *word;
intcount ;
.
structkey {
char *word;
int count;
} keytab [N] ;
156
key, keytab
.
. , ,
structkey {
char *word;
int count ;
};
truct
keytab ,
.
-
.
structkey {
char *word;
intcount;
} keytab [ ] = {
"auto", ,
" break", ,
" ", ,
"char", ,
"const", ,
" continue", ,
" defaul t", ,
1* ... *1
"unsiqned",
"void", ,
" volatile",
"while",
};
.
"" ,
{ " auto", } ,
{ "break", } ,
{ " ", } ,
6.3
157
, keytab
[] .
AXWORD
100
*/
int n ;
char word[AXWORD]
>=)
return mid ;
return -1 ;
<)
158
keytab
main,
qetword,
keytab
, qetword ;
qetword ,
N keytab
, , r
,
(,
) ,
keytab
, ,
( size of)
sizeof
sizeof
sizeof
(mn )
, ( ,
,
sizeof
size_ t <stddef h> )
int
double ,
, ,
#define
N :
6.3
159
sizeof /fif ,
/fdefine,
,
.
getword .
getword, ,
. getword " " ,
,
.
EOF .
/* getword:
int getword (ehar *word, int lim)
*/
!=EOF)
*w++= ;
if (! isalpha ())
*w= '\0' ;
return ;
for ( ; --lim>O;w++)
if (! isalnum(*w = geteh ()))
ungeteh(*w);
break;
*w = '\0' ;
return word [] ;
getword
geteh
ungeteh
4.
getword -
160
isalnum
6-1 .
unqetch
. Getword, , isspace
, isalpha
<ctype. h>
qetword
, ,
. .
6.4
,
,
.
binsearch
keytab
main
Jinclude <stdio.h>
linclude <ctype.h>
linclude <strinq.h>
Jdefine AXWORD 100
int qetword(char *, int);
struct key *binsearch(char *, struct key *, int) ;
/* ~.
main()
u ; ~
char word[AXWORD];
struct key * ;
while (qetword(word, AXWORD) != EOF)
if (isalpha(word[O]))
if ((p=binsearch(word, keytab, N)) != NULL)
p->count++;
for ( = keytab ; < keytab + N ; ++)
if (p->count > 0)
printf( " %4d %s\n" , p - >count, p->word);
return 0;
*/
6.4
16 1
int cond ;
struct key *1ow = &tab [] ;
struct key *high = &tab [n] ;
struct key *mi.d;
while (low < high)
mi.d = 1ow + (high-low) 1 2 ;
if ((cond=strcmp(word , mi.d->word))
high =mi.d ;
1 if (cond >)
low=mi.d+ 1 ;
else
return mi.d ;
<)
return NULL ;
binsearch ,
struct key ; binsearch .
binsearch , ;
, NULL.
, keytab .
binsearch .
1ow high
.
mid = (low+high) 1 2
/*
*/
. ,
high- low ,
,
. &tab [-1] &tab [n)
tab . ,
. ,
,
162
(. .
&tab [n])
main :
for
, ,
, ++
, ""
. , ,
char , int
struct {
char ;
inti ;
};
, .
sizeof
, :
,
structkey *
binsearch (char *word , struct key *tab , int n}
, , ;
6.5
.
,
.
, ;
6.5
163
. ( ,
, , .
?
,
.
.
" " ( ) ;
,
,
- ,
- .
;
.
,
,
. "
now
is the t ime for all good men to come to the aid of their party".
now
18
/"-the
/"men of/
for
all/
/""-
good
"""
"
pa.rty
""" time
their
/ """
to
a.id come
,
n .
, n . ,
,
. ,
, , ,
. ,
164
.
,
.
,
:
struct tnode {
char *word;
int count ;
struct tnode *left;
struct tnode *right ;
/*
/*
/*
/*
/*
*/
*/
*/
*/
*/
};
,
. ,
left
tnode,
tnode .
(
) : .
:
struct t {
struct
* ;
/*
*/
};
struct
struct t *q; /* q
t */
};
,
getword,
getword
main
addtree .
linclude <stdio. h>
iinclude <ctype. h>
iinclude <string. h>
idefine AXWORD 100
struct tnode *addtree (struct tnode * , char *) ;
void treeprint (struct tnode *);
intgetword(char *, int);
6.5
/*
main ()
165
*/
addtree . main
( ) . ,
addtree. ,
(n
)
.
,
addtree
1* add tree :
., w, . * 1
struct treenode *addtree (struct tnode *, char *w)
int cond;
NULL) { / * 'l'r /
= talloc () ; 1* */
p->word = strdup (w) ;
p->count = 1 ;
p->left .. p->right = NULL;
} else if ( (cond= strcmp(w, p->word)) = 0)
p->count++; 1 /
else if (cond< ) / * otuUI , . */
p->left addtree (p->left , w) ;
else / *axo , , ..*/
p->right =addtree (p->right , w) ;
returnp;
if
( =
166
talloc,
, strdup . (
. ) ,
NULL .
, . ( )
strdup
talloc .
treeprint ;
, (
)
1 (
).
, treeprint
.
/* treeprint: in-order
void treeprint(struct tnode *)
*/
if
!= NULL) {
treeprint(p->left) ;
printf( "%4d %s\n", p->count , p->word) ;
treeprint(p->right) ;
: " " 1
,
. 1
,
. ,
, .
,
.
,
.
1
char
struct tnode ,
. 1 ,
(
, .
)? ,
?
,
,
. alloc
. ,
6.5
167
mallo c , . 8 ,
malloc.
malloc
. ,
malloc
void ,
. D~Alloc
strdup
, malloc
char *strdup(char
*)
/*
*/
char
* ;
(char *) malloc(strlen(s)+l) ; /* +1 f o r
!= NULL)
strcpy(p , ) ;
return ;
if
'\0 ' */
6-2 .
malloc
free ; 7 8 .
, .
.
6-3.
" "
. ,
.
168
6-4 .
.
.
6.6 n
(.
table-lookup) .
. 1
idefine.
idefine IN 1
IN 1 . 1
IN
state =IN;
1.
install ( 1 t) ; t
.
lookup ()
. NULL .
-
1
.
. NULL
.
defn
6.6
169
n n
, .
n .
struct nlist { /* : */
struct nlist *next ; /*
char *name ; /* */
char *defn; /* ~ */
*/
};
idefine
ASHSIZE
101
*hashtab[ASHSIZE] ;
/*
*/
lookup
install ,
, .
/* hash :
unsigned hash(char *)
*/
unsigned hashval ;
for (hashval = ; * != '\0 '; ++)
hashval = * + 31 * hashval ;
return hashval % ASHSIZE ;
(. unsiged)
hashtab ;
, n
.
lookup. lookup
n , , NULL .
/* lookup : ro hashtab */
struct nlist *lookup(char *)
{
==
170
for
lookup
install
lookup
; , .
. install NULL
.
==
if ((np = lookup(name))
NULL) { /* */
np = (struct nlist *) malloc(sizeof(*np)) ;
if (np
NULL 11 (np->name = strdup (name) )
NULL)
return NULL;
hashval = hash(name);
np->next = hashtab[hashval] ;
hashtab[hashval] = np ;
else /* */
free ( (void *) np->defn) ; /* ro dfn * 1
if ((np- >defn = strdup(defn)) == NULL)
return NULL ;
return np ;
6-5 .
undef
lookup install.
6-6.
#define
( , ) ,
. getch
ungetch.
6.7typedef
typedef
. ,
6.7
typedef
171
Lenqth
int.
Lenqth
, .,
int:
Strinq
char*,
. .
Strinqp, lineptr[AXLINES]
intstrcmp(Strinq , Strinq) ;
alloc (int) ;
typedef
, typedef . , typedef
extern , sta tic . typedef
.
, typedef
:
/*
/*
/*
/*
/*
. .
*/
*/
*/
*/
*/
Treennode ()
Treeptr ( )
talloc
172
typedef
; . , ,
. ,
typedef ltdefine ,
,
. ,
PFI, "
int",
PFistrcmp,numcmp;
.
,
typedef.
typedef ,
,
n.
typedef
na n
short, int long n. size_t
ptrdiff_t n.
n typedef
- n reeptr n
,
n .
6.8
( )
,
n . n
,
n
. variant n .
n
n, m
int, float
n .
n , , n,
. -
n . :
6.8
173
union u _ tag {
intival ;
fioat fval;
char *sval;
} u ;
; .
u
:
.
;
.
__.
__- >
utype
u ,
==
if (utype
IN)
printf( "%d\n " 1 u.ival) ;
if (utype-= FLOAT)
printf( " %f\n" 1 u.fval) ;
if (utype = SRING)
printf ("% s\n", u . sval) ;
else
printf ( " bad type %d in utype\n", utype) ;
, .
(
) .
,
174
struct {
char *name ;
intflags;
intutype ;
union {
intival;
float fval;
char *sval;
} u;
} symtab [N] ;
ival
symtab[i] .u.ival
sval
*symtab[i] . u.sval
symtab[i] .u.sval[O]
,
, "
" , .
:
, .
.
() 8
,
.
6.9
,
;
, ,
.
6.9
175
.
, , ,
.
char int.
, "
" ,
#define EYWORD 01
#define EXTRENAL 02
#define STATIC 04
enwn {
EYWORD
= 01 ,
EXERNAL
= 02, STATIC = 04 } ;
2.
,
2.
i f ( (flags &
(EXERNAL
1 STATIC) )
=)
.
,
,
.
,
,
"" .
. n ,
#define n ,
:
176
struct {
unsigned int is_ keyword : 1;
unsigned int is_extern : 1;
unsigned int is_static : 1;
} flags;
flags
.
. unsigned int
.
. ,
if (flags. is_extern ==
&& flags.
is_static ==)
,
. ,
. ;
( )
.
.
,
.
, ,
;
.
int;
signed unsigned.
,
&
7:
1 1
1 1
ANSI 1
; 1
<stdio h> 1
<string h> 1 <ctype h>
7.1
3 33
;
1 ,
1
( carriage return)
linefeed
177
getchar :
178
getehar
, EOF
. EOF
<stdio.h>.
-1 ,
EOF, .
,
<;
getehar ,
prog
prog <infile
prog infile .
prog ; ,
argv .
" <infile"
, ,
; ,
otherprog 1 prog
otherprog
otherprog
prog n
prog .
( .
pipes)
intputehar (int)
:
putehar ()
putehar
n ,
EOF . ,
prog >outfile
n
outfile.
n n,
prog 1 anotherprog
prog , anotherprog.
printf, , n
putehar printf n -
n .
/
,
7.2
n n .
- printf
179
< >
UNIX
( ,
, /usr/include)
; , getchar , putchar,
printf .
,
:
*/
intc
while ((= getchar ()) ! = EOF)
putchar(tolower(c)) ;
return ;
tolower
<ctype.h>;
. . .
<ctype . h>
7- 1 .
, ,
argv [] .
7.2
- printf
printf .
printf
, ; , .
180
printf
fortnAt.
: 1
1
printf .
. %
, .
.
.
( ,
) .
- , .
, ,
,
, .
- h
%,
short,
( )
long .
.1 .
, .
. 1 printf
d, i
int;
int ; ( )
int; ( ),
abcdef ACDEF 10 1 , 15
int ;
int;
char* ; '\ '
double ;
[-] m. dddddd,
d-
6) .
double ; [-]m . dddddde+- xxili [-]m .ddddddE+- xx ,
d- (n
g, G
double ;
% %
6) .
-4
%f .
void* ;
; %
( )
7.2
printf
*,
181
. , max ,
1114 , ) ;
,
.
.
:%:
:%10:
:%.10:
:% -lOs :
:%.15:
: %- 15:
: %15.10:
:%-15.10:
: hello, world :
:hello, world:
: hello, wor:
: hello, world :
:hello , world:
:hello, world
hello, wor:
: hello , wor
printf
, printf
. , ,
:
printf(s);
printf( " %s " ,s) ;
sprintf
1*
/*
% *1
*/
printf ,
7-2 .
,
.
182
7.3
r n n
printf,
()
. , ,
minprintf
printf
printfe
intprintf(char*fmt , ... )
. . .
...
. Haominprintf
<stdarg . h>
.
, .
va_list
;
minprintf , , "
va_surt
" .
.
. ;
va_arg
va_start .
va_arg ;
. , va_end .
.
printf :
7.4
iinclude <stdarg.h>
/* minprintf : printf
*/
void minprintf(char *fmt , . .. )
scanf
183
va_list ; / * n
char *, *sval ;
int ival ;
double dval ;
va_start(ap, fmt) ; /*
*/
for(p=fmt ; *p ; p++){
if(*p!='% ' ){
putchar (*)
continue ;
arg
*/
switch(*++p){
' d ':
ival=va_arg(ap , int);
printf ("%d " 1 ival) ;
break ;
' f ':
dval=va_arg(ap , double) ;
printf ("%d ", dval) ;
break ;
' ' :
for(sval=va_arg(ap , char *) ; *sval ; sval++ )
putchar(*sval) ;
break ;
default:
putchar(*p) ;
break ;
va_end(ap) ; /*
*/
7 - . minprintf
printf .
7.4 n- scanf
scanf printf 1
, n .
184
scanf 1
fori~~At .
; 1
1
.
printf 1
scanf 1 .
scanf 1
.
.
. EOF ;
1 1
. scanf
,
.
sscanf 1
string 1 format
argl 1 arg2 1 . format 1
.
:
- (%)
%1
h 1 1 L
.
.
. ;
,
.
scanf
1 1
7.4
return,
. ( , ,
scanf
185
carriage
formfeed .)
,
.
7.2.
7.2 : scanf
3;
d
i
;
;
int*
int
( )
( )
char
unsiqned int*
*. (
1)
.
;
% 1
( );
char *,
'\0'
.
e , f,g
float*
% ; .
d, i,
u,
int,
h,
short
( )
1ong
, 4 ,
scanf ,
#include <stdio.h>
main(){
/*
*/
double sum , v;
sum=O ;
while(scanf( "% l f" , &v)==1)
printf("\t%.2f\n", sum+=v);
return ;
186
25 Dec 1988
scanf
scanf ;
. ,
mm/dd/yy scanf :
, ,
sscanf .
scanf
.
scanf.
: scanf sscanf
. :
7.5
187
seanf ( "%d" , n) ;
7-4.
seanf minprintf
7-5 . 4.
seanf /
sseanf .
7.5
,
,
.
eat,
eat
. ,
eatx . cy . e
. . ( )
.
, .
.
,
fopen. fopen
. . ,
( )
, ,
, ,
n ,
188
.
, <stdio . h>
FILE.
FILE *fp ;
FILE * fopen ( char *n&llle, char *mode) ;
fp FILE fopen FILE.
FILE , int , ()
; typedef. ( fopen
UNIX
fopen
8. )
. mode, , ,
.
("r" ), ( " w" ) ( " " ) .
; ,
, , ,
.
, fopen
NULL. ( ;
. )
, .
getc
; ,
.
putc :
intputc(intc , FILE.*fp)
7.5
189
putc fp ,
EOF . getehar putehar, gete pute
, .
,
stderr,
stdout stderr
<stdio . h> .
stdin, stdout
stdin
stdin stdout
,
7 . 1 .
fseanf
fprintf.
seanf
printf ,
;
.
eat .
. ,
. , .
190
#include <stdio.h>
/* cat: ,
main(int argc, char *argv[])
1 */
FILE *fp;
void filecopy(FILE * , FILE *)
if (argc
==
1) /*
r ;
*/
filecopy(stdin, stdout) ;
else
while(--argc >)
if ( (fp = fopen(*++argv, " r " ))
NULL) {
printf( " cat : can' t open %s\n, *argv) ;
return 1 ;
else {
filecopy(fp, stdout) ;
fclose(fp) ;
==
return
/* filecopy: ifp
void filecopy(FILE *ifp, FILE *ofp)
ofp */
int
!= EOF)
,
, ,
cat . fclose
putc .
fclose
7.6
stderr
exit
191
. (
stdin stdout.
freopen. )
7 .
- stderr exit
cat
. ,
,
.
,
.
,
,
stderr
stderr
stdin stdout .
cat
#include <stdio.h>
/* cat: ,
main(int argc, char *argv[])
2 */
FILE *fp;
void filecopy(FILE *, FILE *);
char *prog = argv [] ; 1 * n
*1
if (argc == 1 ) /* r; */
filecopy(stdin, stdout);
else
while (--argc > 0)
if ( (fp = fopen(*++argv, "r")) == NULL) {
fprintf(stderr, "% : can ' t open %s\n" ,
prog, *argv) ;
exit(l);
} else {
filecopy(fp, stdout) ;
fclose(fp) ;
if (ferror (stdout) ) {
fprintf (stderr, "%: error wri ting stdout\n", prog) ;
exit(2);
exit(O) ;
192
. ,
fprintf stderr ,
, arqv []
, ,
.
, exi t,
exi t ,
. ,
;
.
exi t
fclose
.
(main) , return expr
exi t (expr) . exi t
, .
ferror fp.
7.7
n3 33
fgets
getline :
fp line ; maxline- 1
. '\0'. , fgets
line ; NULL . (
getline
, ;
.)
7.7
,
fputs
193
) :
EOF , .
stdinstdout. , gt
'\n',
ut .
fqets
fputs ,
, :
/* fqets : n
ehar *fqets(ehar *, int n , FILE *iop)
iop */
reqister int ;
reqister ehar *;
iop */
int ;
while (= *++)
pute ( , iop) ;
return ferror ( iop) ? EOF :
EOF
ferror ; fputs
qetline fqets:
/* qetline: ,
int qetline (ehar *line, intmax)
=NULL)
*/
194
7-6 .
7-7.
1 5 1
.
?
7-8.
1
.
7.8
.
.
.
7.8.1
n r
strcat ( t)
strneat(s 1 t 1 n)
strcmp ( 1 t)
1
strncmp(s 1 t 1 n)
strcpy ( 1 t)
strncpy(s 1 t 1 n)
strlen(s)
strchr(s 1 c)
strrehr(s 1 e)
n t
NULL
NULL
7 .8.2
int .
7.8
isalpha ()
isupper ()
islower {)
isdigit ()
isalnum(e)
isspaee ()
toupper ()
tolower ()
195
,
,
,
,
isalpha ()
isdigit(e) ,
return , fonnfeed,
, , ,
7.8.3 ungetc
ungeteh
4 ;
ungete .
EOF .
ungete
seanf , gete , g etehar .
fp
7 .8.4 3wtb
system ( ehar * )
, .
. ,
UNIX ,
.
.
exit.
7 .8.5 tb
ma.lloe ealloe
196
. , NULL .
.
malloc calloc
,
,
int *ip;
ip = (int *) calloc (n, sizeof (int)) ;
free () ,
malloc calloc .
,
malloc calloc .
, .
, ,
:
for (p=head;
free(p) ;
!=NULL ; p=p->next)
/*
*/
8 . 7
malloc ,
.
7 .8 .6
20 <math . h> ;
.
double double.
7.8
sin(x)
()
atan2(y , x)
()
log(x)
loglO(x)
pow(x,y)
sqrt ()
()
fabs
197
/ ,
( )
(
10)
(>)
(> )
(>)
7.8.7
rand ()
RAND_ <stdlib . h>.
,
1 (RAND_AX+1 . 0))
(
, .
srand (unsigned)
rand .
rand srand
2.1 .
7-9. isupper
. .
8: UNIX
UNIX
,
, .
UNIX,
, ,
.
,
; ,
ANSI
UNIX,
, , .
; /,
() .
UNIX .
7 /
.
. UNI-
8 . 1
UNIX,
, ,
,
.
, ,
. ,
199
200
UNIX
? ?)
.
, ,
. (
, (.
handle)
MS-DOS . )
;
.
/
,
. ( ,
r.
she11)
1, 2,
, , ,
, .
1 2, /
1/0 (Input/Output-
) < >:
1 .
( .
pipe) .
read write,
read
wri te.
, .
. .
int n_ read
= read(int
int n written
= write(int
8.2
1/0 - read
write
20 1
. ,
.
, -1 . ,
.
1, ( "
" ), 1024 4096,
. ,
.
1 .
, ,
.
*/
char buf[BUFSIZ];
int n;
while ((n= read(O, buf , BUFSIZ)) > 0)
write(1 , buf , n) ;
return 0 ;
syscalls. h
, . BUFSIZ, ,
syscalls. h;
BUFSIZ
read
wri te;
read
read write
getchar, putchar, .
getchar ,
202
UNIX
*/
return (read(O ,
1) -- 1) ? (unsigned char)
& ,
EOF ;
char, read
unsigned char ,
()
getchar,
*/
EOF;
8.3
203
#include <fcntl.h>
int fd ;
int open(char *name , int fiags , int perms) ;
fd = open(name, fiags , perms) ;
fopen, name
int
. fiags
; :
RDONLY
WRONLY
RDWR
Berkley
fd
= open(name ,
O_RDONLY,O);
open
perms
.
,
crea t.
= creat(name ,
perms) ;
-1 .
,
creat
creat
, .
,
perms.
creat
UNIX,
, ,
, , , ,
.
. , 0755
, ,
.
, UNIX-oaa
, .
204
UNIX
cacliiE5aot, rpyna,
: OC'1'llllir1
*/
/* : fl f2 */
main(int argc , char *argv[])
{
int f1 , f2 , n ;
char buf[BUFSIZ] ;
if (argc != 3)
error("Usage : from to " );
if ((f1 = open(argv[1] , O_RDONLY , ))
-1)
error( " cp : can' t open % " , argv[1]) ;
if ((f2 = creat(argv[2] , R))
-1)
error( " cp : can ' t create % , mode % 0 " ,
argv[2], R) ;
while ((n= read(f1 , buf , BUFSIZ)) > 0)
if (write(f2, buf, n) !=n)
error( " cp : write error on fi.le % ", argv[2]) ;
return ;
==
==
0666.
stat,
8.
error ,
printf. error,
printf .
printf,
vprintf
, va_
start . , vprintf vsprintf fprintf sprint .
( 20)
. ,
. close (int fd)
; fclose
,
.
exit
return .
8.4
- lseek
205
*/
va_list arqs;
va_start(arqs, fmt) ;
fprintf(stderr , "error: " ) ;
vprintf(stderr, fmt , arqs);
fprintf(stderr , " \n" ) ;
va_end(arqs);
exit(l) ;
remove
name
8-1. t 7 , read,
wri te, open close
.
.
8.4 n - lseek
:
wri te
read
. , ,
.
lseek,
,
.
fd,
offset,
, 1,
origin .
origin
2 offset
, ,
, . , (
>>
UNIX,
:
, .
" "
fopen),
206
UNIX
lseek(fd , OL ,
) ;
OL;
( long) ,
, lseek ,.
lseek,
. ,
, .
,
-1 .
-1
lseek
long
*/
fseek
lseek, FILE*
, .
8.5
fopen
getc
,
, fopen getc .
, .
: ,
; ;
; ;
/ , , .
8.5
<stdio . h>,
- n fopen getc
207
,
, ( )
.
#define
#define
#define
#define
NULL
EOF {-1)
BUFSIZ 1024
OPEN_ 2 /*
/ * * /
/* n */
/* */
/* EOF n */
/* */
};
208
UNIX
getc ,
. ( tdefine
) , , getc _fillbuf
,
. unsigned, .
,
_flushbuf
getc,
putc
. ,
,
.
fopen .
- .
fopen
; _fillbuf .
include
<fcntl . h>
" syscalls . h "
fdefine R 0666 / * RW
include
n,
rpyna ,
*/
int fd ;
FILE *fp ;
if (*mode != ' r ' && *mode != ' w' && *mode != '')
return NULL ;
for (fp = _iob ; fp < _iob + N_; fp++)
if {(fp->flag & (_READ 1 _WRITE)) ==)
break ; /* found free slot */
if (fp >= iob + N_) /* n o free slots */
return NULL ;
if ( *mode = 'w' )
fd = creat(name , R) ;
else if (*mode == ' ') {
if ((fd = open(name, O_WRONLY , 0)) -- - 1)
fd = creat(name , R) ;
lseek(fd , OL , 2);
else
fd = open(name, O_RDONLY, 0) ;
if (fd == -1) /* couldn't name */
return NULL ;
fp->fd = fd ;
fp->cnt = ;
fp->base = NULL ;
fp- >flag = (*mode -- ' r ' ) ? READ
_WRITE ;
return fp ;
8.5
fopen
fopen getc
209
,
. ,
,
.
getc
_fillbuff . _fillbuff
EOF.
( )
, _ fillbuff
read
.
,
. _fillbuf .
*/
int bufsize ;
i f ( {fp->flag& (_READ I_EOF_ERR))
!= _READ)
return EOF ;
bufsize = (fp- >fiag & _UNUF) ? 1 : BUFSIZ ;
if (fp->base == NULL) /* */
if ((fp->base = (char *) malloc(bufsize)) == NULL)
return EOF ; /* */
fp->ptr = fp->base;
fp->cnt = read(fp->fd , fp->ptr, bufsize) ;
if (--fp->cnt < ) {
if (fp->cnt == -1)
fp- >fiag 1= _EOF ;
else
fp->fiag 1= _ERR ;
fp->cnt = ;
return EOF ;
. _ iob
FILE
{
{
{
} ;
iob[OPEN_AX]
,
,
,
(char * )
(char *)
(char *)
,
,
,
{ /*
(char
(char
(char
210
UNIX
flag stdin
, stdout stderr .
8-2 .
fopen
_fillbuf
.
.
8-4 .
fseek
8.6
, .
ls UNIX-
, ,
, , .
dir - .
UNIX ,
ls ,
. , ,
, , .
, ,
; , - .
,
,
.
fsize.
fsize ls
. , fsize
. ,
.
UNI-
.
. " "
8.6
211
,
. ,
inode-o .
,
. ,
.
Dirent
opendir, readdir
closedir
inode-o
fsize .
version 7 v UNIX;
.
Dirent
inode .
opendir
DIR, FILE
readdir closedir.
dirent. h.
N_, .
#define
14 /*
*/
/*
typedef struct { /* n
long ino ;
/*
char name[NAE_AX+1] ; /*+
Dirent;
typedef struct
int fd ;
Dirent d ;
DIR ;
/*
/*
/*
DIR :
*/
*/
inode*/
'\0' */
.*/
*/
*/
char *name;
struct stat stbuf;
int stat(char *, struct stat *) ;
stat(name, &stbuf) ;
-1 .
212
stbuf
UNIX
inode
. stat </
stat. h>,
struct stat
/* inode
dev t
ino t
short
short
short
short
dev t
off t
st_dev ;
st_ino ;
st_mode ;
st_nlink ;
st_uid; /*
st_ gid ; / *
st_rdev ;
st_size ;
t~e_t st_atime ;
time_t st_mtime;
time t st_ctime;
/* inode * /
/* inode */
/* */
/* ~
stat*/
~* /
~ ~ n~* /
~ n* /
/*
/*
/*
/*
/*
n. ~*/
~ */
n nn
*/
n ~
*/
n inode-o
*/
};
.
#define
#define
#define
#define
#define
/*
.. .
IF 0160000
IFDIR 0040000
IFCHR 0020000
IFLK 0060000
IFREG 0010000
/*
/*
/*
/*
/*
n */
*1
*/
n ~ */
r */
~
n
*/
fstat
fsize .
. ,
;
- , .
(main) ;
fsize .
8.6
#include
#include
#include
#include
#include
#include
#include
<stdio . h>
<string . h >
" syscalls . h "
<fcntl.h>
<sys/types.h>
<sys/stat.h>
" dirent.h"
/*
/*
/*
213
nw
n n
*/
*/
stat */
void fsize(char *)
/* n * /
main(int argc , char **argv)
{
/* n :
if (argc == 1)
fsize (". " ) ;
else
while (--argc > )
fsize(*++argv) ;
return ;
*/
fsize .
fsize dirwalk
. _IF _ IFDR
<sys/stat.h> .
, ,
, & = .
/* fsize: n
void fsize(char *name)
%s \ n ", name) ;
dirwalk
. ,
, ,
.
fsize dirwalk
214
#define
UNIX
1024
/* dirwalk: n fcn
void dirwalk(char *dir 1 void (*fcn) (char *))
dir */
char name[AX_PATH]
Dirent *dp ;
DIR *dfd ;
==
if ((dfd = opendir(dir))
NULL) {
fprintf(stderr 1 " dirwalk: can 1 t open %s\n"
return ;
dir) ;
"
"
))
closedir(dfd);
readdir
,
NULL .
, ".",
" . . ";
, .
,
.
opendir,
readdi r closedir .
v ersion 7 System v UNIX;
<sys/ dir . h>, :
#ifndef DIRSIZ
#define DIRSIZ 14
#endif
str uct direct { /* n */
ino_t d_ino ; /* inode */
char d_name[DIRSIZ] ; / * '\0 1 */
};
8.6
215
ino_t
typedef inode -o .
unsigned short ,
;
,
typedef .
<sys /types . h>
" "
opendir ,
fstat, stat
) ,
(
:
readdir
n* /
int fd;
struct stat stbuf ;
DIR *dp;
if ((fd
= open(dirname ,
O_RDONLY , 0))
==
-1
11 fstat(fd , &stbuf) == -1
1 1 (stbuf.st_mode & _IF) != S_IFDIR
11 (dp = (DIR *) malloc(sizeof(DIR))) -- NULL)
dp->fd = fd ;
return dp ;
closedir
return NULL ;
/* closedir:
void closedir(DIR *dp )
opendir */
if (dp) {
close{dp->fd) ;
free(dp);
readdir read
. (
) ,
,
inode , .
inode static ,
.
.
216
UNIX
*1
static Dirent d ; / *
*/
fsize
, ,
. , " ";
. ,
,
.
,
.
.
8-5.
fsize
inode
8.7 - ()
, - .
.
typedef.
, malloc
.
807
- ( )
2 17
, ,
,
,
malloc
malloc
(., ") ,
, ( )
~i~:n4=91
...... .
..
00
..
.. ... .. ..
00
..
....
. ...... . .
use
..
00
00
00
:= , maiJoc
[}l'] , malloc
1 : ::::::: 1
malloc
., " (
, ,
,
, ,
,
, 5,
malloc,
: ,
,
int ,
double;
long
,
, ;
""
,
218
UNIX
.
,
long .
n. r.
union header
/* r
struct {
union header *ptr ;
*/
/*
( n)
*/
/* */
unsigned size ;
;
Align
;/ * n
*/
};
Align
malloc,
; ,
,
size .
malloc ,
. ,
,
.,.
SIZe
-.....__
malloc
malloc
.
- ( )
8.7
base
m.alloc,
freep
NULL,
219
; , .
, .
(freep)
; .
, ;
.
,
, .
*/
Header * , *prevp ;
Header *moreroce(unsigned) ;
unsigned nunits ;
nunits = (nbytes+sizeof(Header)-1)/sizeof(header) + 1;
if ((prevp = freep)
NULL) {/*
* 1
base . s . ptr = freeptr = prevptr = &base;
base . s.size = ;
==
for
freep = prevp;
return (void *)
if
if
(+1)
freep) /*
= morecore(nunits)) == NULL)
return NULL ; /*
*/
((
*/
morecore .
. -
220
UNIX
morecore
free.
UNIX- sbrk (n) n
. sbrk - 1 , NULL
. -1 char*
. ,
. , ,
sbrk .
,
. ,
malloc
/* morecore:
static Header *morecore(usigned nu)
char * , *sbrk(int) ;
Header *up ;
if (nu < NALLOC)
nu
NALLOC;
= sbrk(nu * sizeof(Header)) ;
if (
(char * ) - 1) / *
return NULL ;
up = (Header *) ;
up- >s.size
nu ;
free ( (void *) (up+1)) ;
return freep ;
*/
==
*/
free . ,
freep, .
. ,
, .
.
- ( )
8.7
/* free: ~
void free(void *)
22 1
*/
Header *bp,
*;
bp = (Header *) - 1; /* n
*/
for ( = freep ; ! (bp > && bp < p->s.ptr) ; = p->s.ptr )
if ( >= p->s.ptr && (bp > 11 bp < p->s . ptr))
break; /* n= : CUIfATa*/
if (bp + bp->size == p->s.ptr) { /* n nbr * /
bp->s.size += p->s.ptr- >s.size;
bp->s.ptr = p->s.ptr->s.ptr;
else
bp->s.ptr = p->s.ptr;
if ( + p->size
bp) { /* n nbr */
p->s . size += bp->s.size;
p->s . ptr = bp->s.ptr;
else
p->s . ptr = bp;
freep = ;
==
. typedef
union
( sbrk
)
. ,
.
size, .
calloc, malloc .
8-7 . malloc
; free
.
.
8-8. bfree (, n)
n malloc free .
bfree,
.
1.
n n n n-
, ,
, n, n ,
. n
, n
n, n
.
, ,
. ,
ANSI
,
2.
n ()
. n
12
1,
. nn
12, n .
2.1
: , ,
, , n n. , -
223
224
, ,
( " ")
.
, .
,
.
2.2
/*
* 1.
2.3
.
;
. .
31 ; .
(All. 2) .
:
2.4 n 3
, :
auto
break
char
const
continue
default
do
double
else
enum
extern
float
for
goto
if
int
long
register
return u
short
signed
sizeof
static
struct
switch
typedef
nion
unsigned
void
volatile
while
225
, ,
fortran asm o
const, signed vo1ati1e AN $1
; enwn void ,
; entry, ,
2.5
2 :
-
-
2.5. 1
, ,
, n
8 9
10 15
(r
u,
unsigned) ,
1ong
( 4 )
, 11
:
1ong
226
2.5 .2
''
,
.
' ;
, ,
N L (LF)
\n
\t
VT
\v
\b
\\
\?
\'
\"
CR
\r
FF
BEL
\f
1, 2
000
hh
\ xhh
, .
\ ( )
NUL .
\xhh
, .
,
, . ,
char
(.
slgned) ,
char.
\ ,
.
,
char .
L, , L ' ',
wide) . wchar_ t ,
<stddef. h> .
(.
wchar_ t.
, ,
wchar_ t
char ;
.2
227
2..
,
, , , (+
-)
f ,
F,
1 L .
.
( ) ;
, (
float , L
. ; F
1ong doub1e , doub1e .
2.5.4
( . 4)
int.
2 .6
" .. . ". " " static
( 4 )
.
,
, .
.
,
\ 0,
,
.
,
L , L "x".
"
wchar_ t ".
.
,
,
ANS I ,
.
, ,
228
3.
,
.
; ,
, " ".
" opt",
, ,
t }
l.
n ,
n
4.
, , :
;
; ; ; .
, ,
, :
mun.
;
.
, , , . .
,
.
Al l .
4. 1
( ):
. ,
, .
.
,
auto ,
register
( )
.4
229
,
.
, ,
static.
, ,
.
,
sta t i c;
.
, , ,
extern ; .
4.2
.
h>
(char)
. 1<0
char ,
char , ,
,
.
,
; ,
signed c har,
, .
unsigned char
signed char .
char , ,
short int, int long int . int
. .
,_,
,
.
int ,
,
2"
,
na
u nsigned ,
230
(.
overflow) .
,
.
(float) ,
,
.
long double
double;
long float
( . 4) . ,
.
,
.
char int
, ,
.
double .
void
float, double
long
4.3 n
, :
;
;
;
;
.
4.4
n .
const
; volatile -
23 1
. . 2.
;
(.
lvalue)
. ;
, *
. " " El
2 El .
3
, ,
.
. 5 ;
.
.1 ()
, ,
,
.
int
int;
unsigned int.
( ).
.2 3
, ( )
232
. ,
, .
. n
,
;
. ,
, ,
.
6.4 n
.
.
.
.
, , .
.
-,
long d o uble ,
long double .
- , double,
double .
-,
float ,
float .
- , ; -
233
int,
long int ,
unsigned
unsigned int
long int .
-, long int ,
long int .
- , unsigned int ,
unsigned int.
-, int.
2 . , floa t n nn
long int ;
long int ;
unsigned int
, ; n n
n . ,
n ,
unsigned
.
.
n n
, , n
.
.
,
;
( 7 . 7) .
;
( 7 . 7) .
,
void* ,
, ,
.
,
.
,
.
, . .
cast
( ) ( 7.
8 .8 ).
; .
, .
.
-
234
,
.
;
" " ,
char .
. , void*
.
,
.
; ,
,
.
A6.7void
( ) void
, ,
e-void .
void
, , ( 9. 2) ,
" "
(,) ( 7 .18) .
void .
,
void
void
6.8
void
void*
.
, .
, . ,
void*
void*
char* .
void*
ANSI
,
.
.7
235
7.33
, ,
, n + ( 7
7)
7 ol 7
n
l n
n ,
,
, ()
, n
, n
n , n
n n
n n
,
, n
n n
n n
n
,
n
;
7.1
n " ",
n
" n "
n & ++ ,
-- , sizeof,
"
n n
"
" ",
236
7.2
, ,
-:
( )
- ,
.
.
( ) ,
, .
- .
, 2. .
-. "
char"
( , "
wchar_ t " ) ,
(wchar_ t) .
7.
, .
-,
.
.
7 .3
.
-:
-
- {]
- (-- )
-.
-- >
-++
-----:
- -
---, --
.7
237
7.3.1 3
.
"
1"',
; .
El [2] ( )
* ( (El) + (2))
8 . . 2 .
7.3.2
,
( 7 .17),
.
,
7 . 1) "
" .
" "
. ANSI
. .
; (
) ,
. " ()" "
() "
.
,
; .
,
. ,
.
.
238
; , , .
, .
8. . 10. 1 .
,
: (
,
float
. 1)
doub1e.
,
.
. ,
,
, .
,
,
.
,
,. "
( , ... ) .
,
;
, ,
.
.
.
.
, ,
. .
7 .3.3
.
,
. ,
.
.
.7
239
n n ( - >) n
n -. n
n ,
.
n n ,
n n ; .
1-> (*1) . . . .
; ,
. ANSI .
7.3.4
n
++
--n n .
n.
, n ++
--.
; (
7. 7) n ( 7 . 17) n
n n. .
7.4
n rpynpa .
- :
-
++-
---
- - ->
sizeof -
sizeof (-- )
-:
7.4.1
n ++ --n .
n
++
--
1 . -
240
()
;
( 7. 7) ( 7 .17)
.
.
7.4.2
& .
,
register , .
.
, " ''
7.4.3 ()
*
. ,
, ,
. " ", .
7.4.4
+
.
. .
+ ANSI .
-
7.4 .5
.
.
1; .
.
.7
241
7.4.6 3
- ,
.
. ,
.
, -
. .
7 .4.7 r r
!
,
7.4.8
int .
sizeof
sizeof
.
, .
sizeof
char
1;
,
: n n
.
.
;
<stddef . h> ( )
size_ t .
7 .5
.
-- :
(--) --
242
.
.
8.
7.6 n n
* , 1,
- :
* --
- 1 - -
-
% - -
.
.
; ,
. ,
)
(a/b*b+a%b
7.7
- .
, .
,
-:
-
+ -
- - -
+ .
.
.
,
. ,
,
p+l
.7
243
, .
.
.
- .
,
.
,
1. ptrdiff_ t
<stddef. h>.
;
, (+ 1) -
1.
7.8 3 .
<< >> .
.
. ,
.
u--:
u-
--
--
<< -
>> -u
1<<2 1 ( )
2 ; 2 2
1>>2 1 2 .
22 , 1
; .
7 .9
,
;
a<b<c
(a<b)
<,
(a<b)
1.
244
-:
--
< - -
> --
<= - -
- >= - -
< ( )
, > () , <= ( )
>= (
1 int
( ) ;
; ,
; ,
p+l
p+l
7.10 3
-- :
-
- -
== -
--!= -
()
!=
( )
( a<b=c<d
e=l
a<b c<d )
, :
, voido
.7
245
7.11 n
-:
- -
&
--
;
.
.
7.12 n n
- - :
-
--
& -
;
.
.
7.13 n
-:
--
- 1--
;
.
.
7.14r
--:
-
--
&& -
&& . 1
, . & , &&
:
; , .
, -
246
1 . ,
int .
7.1 5 r
- - :
- -
--
11
1 1 --
. 1
, .
1 , 1 1
:
; ,
1.
1 , . ,
.
int.
7 .1
-:
--
--
? : -
;
, , ,
. .
,
,
. void , ,
, .
, ,
, . void ,
,
v oid , . ,
,
.
7.17 33 3
;
.
.7
247
-- :
-
- -- - -
--:
*=
1= % =
+ = -= <<=
>>=
&=
1=
,
: , ,
. ,
const;
const .
,
.
=,
.
: ,
;
;
void,
const
volatile . El = 2
El = El 2 El .
7.18
:
--
--
.
, , ( 7.3 .2 )
( 8.7),
,
, , ,
f(a,
(t= ,
t+2) ,
, .
248
7.19 33
- :
-
, ,
, ,
.
,
, ,
;
sizeof.
, , ,
;
, .
, , ,
. (,
sizeof.)
;
& ,
.
&
.
/
.
#if; sizeof
15.5.
8
;
. .
.8
249
- -- .,;
--
; ()
.
- :
u- -- - .,
- - - opt
-- - <
--:
-
--, -
-:
( 8.5);
.
,
, ;
.
8.1
:
--u-:
auto
register
static
extern
typedef
4. 4.
auto
register
. , ,
.
register
auto
250
; . ,
register,
&
, , .
register,
auto.
static
, .
,
; All. 2.
extern,
All. 2.
typedef
; . 9.
.
:
auto ;
extern;
static
; AlO - All.
8.2
:
--u:
void
char
short
int
long
float
double
signed
unsigned
- --
-u
typedef-ue
long short
double .
signed unsigned
.8
251
char. int.
signed char ;
.
,
int.
, ,
.
--:
const
volatile
.
const ,
volatile .
const volatile ANSI .
const
, , n . volatile
n n n
. n , -n
/ , n n
volatile
n n
n n.
n n
const n
.
.
, .
-- -:
-- opt { --
--
-- :
struct
union
252
--
:
- -:
-
-- -
-:
- - --;
--:
- -- opt
- -- opr
--:
-
--, -
,
. , ,
. , , ;
.
-:
' : -
--
{ - -
:
--
,
mun.
, , ( )
typedef 1 .
1 -
.8
253
. ,
} .
. , ,
;
,
.
-- ;
,
.
( All . l) ,
.
ANSI.
, ,
;
.
.
, .
,
. ,
ANSI .
. (
)
signed int
int
n n.
, , .
n
, , ,
. ,
n,
.
ANSI
"
", .
254
. ,
.
;
.
.
.
.
, .
struct tnode {
char tword[20] ;
intcount;
struct tnode *left;
struct tnode *right ;
20 ,
. ,
struct tnode
, *;
, .
sp->count
count
s . left
,
s.right->tword[O]
tword
r,
. , -
255
:
,
, :
union {
struct {
int type ;
} n;
struct {
int type ;
int intnode ;
} ni ;
struct {
int type ;
floa t fl.oa tnode ;
} nf ;
} u;
8.4
.-:
.
- , .
.:
.
. = ..-
256
it .
=,
1,
. =
;
.
,
.
uu u u
;
. uu- uu
,
;
uu - uu
.
n , ,
.
:
:
opr u-
-:
()
- {- opr ]
u - ( - - -)
u - ( -uu 0' )
:
* - - opt
* --r
-u u -u:
- -u
u-uu-u ll-- u
.8
257
,
; .
.
.
,
-.
,
.
,
.
( 8 . 2) , "
D", D .
.
D
.
D
( Dl )
Dl D.
, .
8.6.1
D D
* --opt Dl
Dl "--
" ,
"- - -
- ':
, .
,
int*ap[) ;
258
, [] Dl ; " int * []
" (n)
" int",
, " " ,
, "
int"
pci
8.6.2
Dl {-.,
TDl " -- :
D " -- "
-, ,
,
, ,
, (
)
,
, ( AlO 2) ,
( 8 . 7) . ,
floatfa[17] , *afp[17] ;
.
,
.8
259
1 d :
; .
x3d 1 xd[i]
[k]
. "",
d [ i
[ ]
int.
d [ i]
* (El+E2) .
El [2]
, 1
+ ( . , 7 . 7 , 7. 7) ,
Ele 2 1 El [2] 2- El
, xd[i] []
[k]
* (d[~] []
+ k).
d[i [] 7 . 1 "
"
7 . 7,
.
(n )
8 .6.3
D,
Dl
(- - - )
"
TDl
"--
"--
- - - "
-- - :
-
r-
-
-
-:
-
- -r
260
,
. ,
void . ",
... ",
, 7 . . 2
, ;
AlO. 1. ,
register,
.
,
,
.
.
D, D
D 1(--)
" ,
D1
"
--
"--
". ( )
--u:
- -,
,
( 10 . 1) .
.
.8
261
strcpy int, ,
, .
. rand int.
ANSI .
" "
,
:
.
,
void
.
..
... "
, ,
<stdarg. h>,
, .
++
8.7 n3
, -
.
=, ,
. ,
.
:
- -
{ -}
{ -,}
- :
-,
7 .19.
auto register , ,
. , ,
,
.
,
. ANSI ,
.
262
,
( ) .
, . .
,
.
, .
.
.
, ,
.
;
.
;
. ,
2 . )
wchar_ t.
, , ,
; ,
, ,
.
.
. "
" , .
ANSI
, .
:
, ,
, ,
; n
. ,
,
;
.8
263
int [] = { 1 , 3, 5 } ;
,
floa t
[ 4] [3]
={
{1,3 , 5} ,
{2,4,6},
{3,5 , 7},
};
:
1 , 3, 5
[1] , [] [2] .
[1] [2] .
( 3] .
(], .. [] [] , []
floa t
[ 4 ] [ 3] = {
1 , 3, 5 , 2 , 4 , 6 , 3, 5 , 7
};
, [
.
, [1] [2]. ,
floa t
[ 4]
( 3]
={
charmsg[]
8.8 n
n,
sizeof)
264
. --,
.
-- :
- - -opt
-:
t --
--:
( -)
-- opt [- ,
. ,
int
int *
int*[]
int (*) []
int * ()
int (*[]) (void)
", " ,
", "
".
8.9 Typedef
,
typedef
;
. typedef .
typedef-ue:
typedef -
.8
265
( . ) . ,
typedef
.
,
Blocknob ;
extern Blockptr bp ;
Complex z , * zp ;
.
;
typedef
zp
long,
bp
long,
. , b lon g
.
typedef
,
.
extern Blockno ;
Blocko,
8 . 1 n
,
( , long
long int) .
, ,
. 8) , typedef
,
.
.
266
9
, .
.
.
:
-
-
-
--
-
9. 1 03 (.
labeled)
.
- :
default:
( .
label)
goto .
. All.l.
9. 4) . .
(
) .
9.2 33
,
-:
r ;
267
,
;
9.3
, ( , "" )
-:
{ -
,- opt }
-:
-:
-
f
, (
All ol) ,
All) ;
static ,
9.4 3 3
--:
if ()
if () else
swi tch
()
268
if ,
,
, . ,
. else
else if else .
swi tch
,
. switch .
( 9. 1) .
( .1) ,
. swi tch ,
. defaul t
defaul t
, .
defaul t ,
swi tch .
in t
swi tch
9.5 3
.
-- :
while ()
do apea while ();
for (opt ; opt ; upt )
while do ,
;
. while , (),
, ; do
for ,
. .
. 9
for
269
1
. .
. continue 1
for
(l ; 2;3)
l;
while (2) {
}
.
l , , .
9.6
.
-:
goto ;
continue;
break;
return opf
goto , (
9 .1) .
.
continue
.
cotinue . ,
while ( ... )
do {
for ( ... )
contin :
contin:
contin :
} while ( . .. } ;
continue
goto contin .
break
270
switch ,
;
.
return.
return
, .
return . .
1. n
( )
; ,
.
- :
-
-- -
-:
-
.
,
10.1
-:
- opr - opr
-
,
, exter
static;
All. 2.
, , ,
void, . -
.10
27 1
; . .
, (
8.6 . ) .
- (---)
- (- opr)
-
. ,
typedef .
, ,
;
.
void , ,
", .. . "
. .
,
, .
int .
, ,
register.
,
(,
" mun",
"
mun",
" mun"
" mun".
, ;
7 . .
2.
ANSI .
, ;
double.
float
272
intb, inte)
intIAx(inta ,
intm;
?:
m= (a>b)
b;
) ,
intmax(a, b,
inta, b, ;
/* . . . */
int max (, b,
.
) ,
int , b,
10.2 w
,
. " "
,
extern; ,
, extern statie.
,
, .
. 10. ,
,
( 8 . 3)
. ,
( 8. . 2) , ,
, ,
. , ,
,
.
statie , ;
.
11 . 2.
A.ll
273
extern
. 1
.
.
1 1
.
1
.
. 1
.
UNIX
1
1 .
1
1 .
11. nop3yBatbe
, : 1
;
1 1
.
11 .1 r
274
, ,
. : , ,
typedef enum ;
; , ;
.
.
;
, , , ;
r
.
,
.
.
;
.
,
.
. , ,
) ( )
, ,
11.2 3
, .
,
.
AlO. 2,
static,
extern ,
.12
275
extern
,
,
, .
12.
,
. #,
, .
;
( ) .
; (n
12
.2
#include
( 12 .
4) ;
. ,
,
.
, , .
1.
, ,
12 .
1,
.
,
.
2.
, ( 12. 2)
. ;
.
, (
12.3-
4.
Al2.10).
; .
. ,
,
.
276
12.1
??=
??/
?? '
?? (
??)
??!
#
\
[
]
1
??<
??>
??-
ANSI .
12.2
\
.
12.3
dejine --
;
. #define
,
.
(,
,
,
.12
277
ft undef
. tundef
.
(,
),
.
;
, .
, .
.
,
.
.
##,
, .
. ,
,
i,
.
\, "
ti ,
ii,
.
11.
ti
1
. 1
1
;
.
#,
.
n n nn n
ANSI
278
# ##,
, ,
( )
, "
" ,
#define ASDIFF ( , b)
(()>
(b) ?
()-
(b) : (b)-
())
,
,
, ,
,
"/ % "
tempfile (/usr/tmp)
#define t
( , )
##
: ##
,
cat ( 1 , 2) 3
) 3 (
)
,
#definexcat(x ,
cat(x , y)
xcat ##
, ASDIFF(ASDIFF(a , b) ,)
. 12
279
12.4
. --
>
", ', \, /* .
.
lt include "
--
"
ycnee,
. , \, /*
,
, > .
,
f include --
;
linclude
12.5 n
,
- :
ft if -
ft ifdef
ft ifndef
280
elif-eou:
elif-uuja
elrif-eou opt
elif-uuja:
lf elif -
l-:
/-
l-:
lfelse
lfelif
; .
. " "
1
; .
lfif
lelif
lelif lelse 1 1
.
lelse
lfelse .
- .
#if lfelif .
1
defined
defined
( )
l lL
OL .
OL.
1
.19)
' 1 sizeof 1
(cast)
.12
28 1
#ifdef
#ifndef
# if defined
# if ! defined
#elif
defined ,
, .
12.6
,
# line
# line
" --
"
, ,
. , .
.
12.7 rpewa
12.8 Pragma
# pragma --
o pt
282
12.9
#
.
12.1
. ,
LINE
defined, .
FILE
DATE
"mm dd "
" hh :mm: "
D
1 .
1,
.
,
.
13.
. , .
, -, - , ,
, - ; n
.
.
,
.13
283
" " ( -)
opt,
. , tdf
- typedef-ue ,
-.
if'-else.
--:
-
-- -
-:
-
-:
- opt -t
-
:
- -- .;
-:
-
- :
--- - opt
- - op t
- - opt
---:
mun :
void char short int long float double siqned
unsigned ---
typedef-ue
-:
const volatile
---:
-- opt { -
}
--
'
284
--:
struct union
--:
-
- - -
--:
-
--, -
-:
-:
-- --;
--:
- -- opt
- -- '
--:
-
--, -
-:
opt: -
-:
enum opt { -}
enum
-:
-,
= -
:
opt -
.13
-:
()
- [- opr]
- (---)
- (-opt )
:
" -- opt
"--.,
--:
-
-- -
---:
-
- ,
...
-:
-
- , -
-:
-
- - opt
-:
-,
:
--
{ -}
{ -, }
-:
-,
--:
- - -opt
-:
opt --
285
286
-_m-:
(-)
-- opt { -
-- opt (--- )
typedef-ue:
:
-
-
-
--
--
-
-:
:
- :
defalt :
-:
.,;
-:
{ -opt - ,}
-:
-
--:
if()
if() else
switch ()
--:
while ()
do while ();
for (,; ,; )
.13
-:
goto ;
contine;
break;
retrn opf
:
--
, --
--:
-
- -- --
assignment-operator:
= *=!= %= += -= <<= >>= &= = 1=
-:
--
--? : -
-:
--:
--
--ii --
--:
-
-- && -
-:
--
-i --
--:
-
-- -
-:
--
- & --
287
288
--:
-
-- == -
-- != -
- :
--
-
< --
> - -
<=
>= --
--
--:
--
-- << --
-- >> --
--:
-
-- + -
-- --
-:
* - -
- 1 --
-
% --
--:
( --) --
-:
++
--
- --
sizeof-
sizeof ( -- )
:
& *+ --!
13
289
-:
-
- []
- (--)
-
-
->+
++
- --
-:
()
--:
--
---, --
:
-
-
-
-
, ,
,
-:
# define --
# define (, .. , )
--
# ndef
# inclde < -- >
# inclde "-- "
# line " -- "
# line
# error -- opt
# praga -- opt
#
-
290
-:
if-uuja:
# if -
# ifdef
# ifndef
elif-eou:
elif-uuja
elif-eouopr
elif-uuja:
elif-
l-:
l-
l-:
#else
ANSI
. ,
,
.
;
; "
"; . . , ,
.
,
:
<assert.h> <fioat.h>
<ctype . h > < limi ts . h>
<errno. h> <locale. h>
<math.h>
<setjmp. h >
<signal . h >
<stdlib.h>
<string.h>
<time.h>
ltinclude <>
.
. .
,
,
.
1. :
<stdio.h>
, <stdio . h >
.
29 1
292
UNIX, .
;
'
\n' .
' \n'
) .
,
, .
;
.
FILE ,
. " "
" ", .
,
tderr
stdin, stdout
1.1
. size t
sizeof .
"r "
" w"
;
,
" "
;
,
" r+ "
( .
" w+ "
" + "
),
, , ,
,
.
fflush
. b ,
.1
<stdio.h>
293
"rb" "w+b", .
FILENAE_AX .
FOPEN_
FILE *freopen (const char *filename, const char *mode , FILE *stream)
freopenja
. , NULL . freopen
stdin , stdout stderr .
int fflush (FILE *stream)
, fflush
, ; ,
. EOF ,
. fflush (NULL) .
.
.
"wb+"
tmpfile
NULL
L_ tmpnam . tmpnam
;
_
. tmpnam , .
294
int setvbuf (FILE *stream , char *buf , int mode, size_ t size)
setvbuf ;
.
_ IOFF
_ IOLF
, _IONF .
buf NULL, ,
. size
. setvnuf .
1.2 33
printf .
i nt fprintf (FILE *stream , const char *format , ... )
fprintf
stream
format. ,
. :
, , ,
fprintf. %
. % , , :
( )
-,
+,
: ,
.
: , n
( )
#,
n . ,
. , n
. , ,
G,
f , g,
G , ; g
.1
<stdio.h>
295
,
.
, nn (
, ) .
n , ,
,
, , n.
, n
n ,
, ,
q G , n
( n
)
- h, 1 ( ), L . " h "
short unsiqned short ;
" 1" lonq unsiqned lonq . " L "
1onq doub1e .
, n
*.
n ( )
(), () ()
int .
n .l .
n % ,
.
, '\'
. ,
'\0 ' .
296
n . 1
printf
d, i
int ;
int ; ( ) .
unsigned int ; (
) , abcdef ACDEF
.
int;
char* ;
'\0'
double ; [- ]mmm.ddd,
d .
,
double ; [-]m.dddddd
[-]m.dddddd
, d
. ,
g, G
double ; % %
-4 ;
%
void *;
f . .
. )
int * ;
printf
: %
printf ,
.l
arg 1
va_ arg.
<stdio.h >
va_ start
<stdarg. h> 57.
297
1.3
scanf .
1
. retur
. :
- 1 .
- ( %) 1
.
- % 1 *
1
h1 11
. 1
. * 1 %* 1
l , ; .
;
.
scanf 1
. ( ,
, , , m . )
.
.
2.
d 1 i 1 n 1 1 u h
short int 1 1 ( )
1ong . 1 f 1 g
1 doub1e
floa t 1 L 1ong doub1e.
298
scanf
.2
n ;
int*.
int*. (
) ( )
( ) ;
( )
unsiqned int* .
char* .
int* .
; int* .
,
; 1 . '\ '
n
;
,
%ls .
char*,
) ;
' \'
e,f , g
n ;
+-,
float* . float
printf
( " % " ) ;
void*.
n ;
int* .
[ ... ]
[] ... ]
].
npunaza ;
' \ '
[ ... ] ... ]
char* .
%. n .
].
.1
<stdio.h>
299
1.4
;
'\ '
. fgets
NULL
EOF
gete (stdin) ,
'\0' .
NULL
pute ( , stdout) .
300
EOF
. ungetc EOF
.
1.5 3 3 33
feof
ferror .
1.6 3 n3
stream ;
. ,
offset origin , _ (n
)
, SEEK_CUR
( ) SEEK_END ( )
, offset ,
ftell ( origin _) . fseek
.
fseek
(fp,Ol,
_ );
. l
<stdio.h>
301
clearer(fp) .
int fgetpos (FILE *stream, fpos_ t *ptr)
fgetposs stream *ptr ,
fsetpos. fpos _ t
. fgetpos
.
61.7 3 rpewa
.
. ,
stream.
strerror .
302
2. :
<ctype.h>
<etype. h> .
int
EOF unsigned ehar ,
int. ()
, .
isalnum(e)
isalpha(e)
isalpha(e)
isupper ()
isentrl(e)
isdigit(e)
islower ()
isdigit(e)
isgraph(e)
islower(e)
isprint(e)
ispunet(e)
isspaee ()
, , ,
, ,
isupper ()
isxdigit ()
ASCII ,
020
( ' ')
( '-') ;
Ox7F
(DEL).
, :
int tolower ()
int toupper ()
, tolower () ,
toupper () ; .
3. :
<string.h>
<string. h>.
mem .
str;
mermnove ,
, .
unsigned ehar.
eonst ehar* ; n
size_ t;
t ehar* ; et
int ehar.
ehar*strcpy (, et)
ehar*strncpy ( . et, n)
' \0';
ehar*streat ( , et)
et
303
et ;
et
'\0 '
et
ehar*strneat ( , et, n)
et
'\0 ';
intstrcmp(es, et)
es<et,
intstrncmp(es, et , n)
es=et
et ,
es>et
<
>,
>,
ehar*strehr(es ,
,
NULL
ehar*strrehr(es ,
NULL
size t
et)
strespn(es ,
et
ehar*strpbrk(es, et)
et
et
NULL
ehar*strstr(es,et)
et
size_t strlen ()
ehar*strerror(n)
NULL
ehar*strtok(s , et)
et ;
strtok ( , et) ,
et . e-NULL ,
et;
'\ '
. ,
NULL
,
. strtok
NULL .
et .
mem ... -
304
; .
int
unsigned ehar.
n et
memepy ,
intmemcmp(es, et, n)
n
strcmp
void* memehr (,
et ;
n)
NULL
void* memset (,
n)
n .
64. :<mth.h>
<math. h> .
EDOM ERANGE
<errno .h>)
HUGE_ VAL
double
. ,
errno
D ;
double .
n , UGE_VAL
,
errno
ERANGE .
, ;
ERANGE
double .
errno
double, n int ,
sin(x)
()
t&n(x)
asin(x)
sin-L()
[-1,1].
[ -pi/2 , pi/2 ,
()
- 1 () [ ,pi ]
atan ()
atan2(y,x)
sinh(x)
,
tan-L() [ -pi/2 , pi/2] .
t&n-1 (y/x) [-pi ,pi].
[-1, 1] .
cosh ()
tanh(x)
()
-'
log(x)
loglO(x)
pow(x 1 y)
xr.
ln ()
305
>.
log10 ()
<stdlib.h>
>.
= <= 1
< .
sqrt ()
1 >=.
ceil ()
1 double.
floor ()
1 double .
fabs(x)
ldexp(x 1 n)
*2 "
f r
int*exp)
1 1
[ 1/2 1 1) 1 2
*. 1 .
m d f
double*ip)
1
. *ip 1
.
fmod(x~y)
! 1 . 1
.
65. : <stdlib.h>
<stdlib. h>
strtod
*)
int ;
(char**)NULL 1 10).
(int) strtol ( 1
strtol ( 1 (char**)
306
, UGE_VAL ;
.
errno
ERANGE.
*np, np . base 2 36 1
base
8 1
1
16;
1 .
16.
10 base-1;
errno
ERANGE.
. 1 .
void*malloc(size_tsize)
malloc
size 1 NULL .
.
realloc NULL
1 * .
: <stdlib.h>
307
raise(SIGART).
. status
, .
EXIT_SUCCESS
EXIT_FAILURE,
, .
fcn
;
.
void*bsearch(constvoid*key,constvoid*base,size_tn , size_tsize,
int (*cmp) (constvoid *keyval, constvoid *datum))
bsearch base [] ... base [n-1]
*key. cmp
( )
( )
base
. bsearch
NULL
308
int .
long .
div_tdiv(intnum, intdenom)
div num/denom.
int quot rem div_t.
. r: <assert.h>
assert
assert () ,
assert
stderr
, ,
FILE
LINE
assert
.8
7. r:
<setjump.h>
309
<stdarg.h>
<stdarg. h>
.
lastarg f
. f
va_list
va_listap;
va_start
:
va_arg
va_ arg :
f.
8. :
<setjump.h>
<serjump. h>
,
n.
310
i f (setjmp(env) == )
/* n n*/
else
/* n longjmp */
void longjmp ( jmp_ buf env , in t val
longjmp
setjmp , env,
setjmp
val.
setjmp .
longjmp ,
e-volatile
setjmp
setjmp .
9. rn:
<signal.h>
<signal. h>
,
SIGART , ,
SIGFPE
abort
SIGILL , ,
SIGINT , , interrupt
SIGSEGV , ,
SIGTER ,
signal handler ,
SIG_ERR n .
sig ,
; -
.10
(*handler) (sig) .
handler
<time.h>
311
1. :
<time . h>
<time.h>
. 1
1 , .
time_ t 1
tm :
int tm_sec;
int tm_min ;
int tm_hour ;
int tm_mday ;
inttm_mon ;
int tm_year;
int tm_wday ;
int tm_yday ;
int tm_isdst ;
clock_ t
struct
(0 1 61)
59)
(0 1 23)
(1 , 31)
(0 1 11)
1900
(, )
1 ( 1 365)
tm_isdst
1 .
clock_tclock(void)
clock
1 -1
.
clock ()
/CL_PER_SEK .
312
*tp
time.
mktime
-1 .
*tp
asctime(localtime(tp))
struct tm *gmtime (const time_t *tp)
gmtime *tp .,
" (. Coordinated Universal ime - U). NULL
u . gmtime .
struct tm *localtime (const time_t *tp)
local time *tp
size_t strftime (char *, size_t Slll4x , const char *fmt, const struct
tm *tp)
strftime
*tp, fmt,
printf. (
' \') . %
smax . strftime
,
'\'
1114 .
%b
.ll
: <limits.h> <floath>
%d
(24- )
%!
(12- )
%m
(01-31)
(00-23)
(00-11)
(001-366) .
(01-12) .
(00-59) .
%U
31 3
(00-61).
( 1- )
(00-
53) .
%w
(-
%W
( 1- )
%Z
%%
%.
(00-53).
(00-99) .
. ;
BIT
UCAR R
char
MIN
char
MIN
char
IN
32767
int
IN
MIN
-32767
int
LONG
2147483647
-2147483647
long
LONG MIN
long
314
+127
signedchar
R
-127
MIN
signedchar
+32767
short
SHRT MIN
-32767
short
255
UCAR
unsigned char
UINT
65535
unsigned int
ULONG
4294967295
unsigned 1ong
USHRT
65535
unsigned short
, <float. h>,
. ,
FLT RADIX
FLT ROUNDS
2 , 16
FLT DIG
FLT EPSILON
1-5
FLT
FLT
FLT
DIG
, 1.
+ ~ 1 .
FLT_ RADIX
1+37
FLT MIN
FLT MIN
1-37
n ,
FLT_RADIX"-1
10n
DBL DIG
10
DBL EPSILON
1-9
DBL
DBL
DIG
, 1.
=1.
FLT_RADIX
1+37
(double)
.11
DBL
: <limits.h> <floath>
DBL MIN
lE-37
n,
315
FLT_ RADrxn- 1
(double)
DBL MIN
FLT RADIX
8: rn
,
.
;
,
.
& ,
. ,
ANSI
, ,
, .
,
.
. , ;
,
,
.
, ; ;
(ft) ;
(#ft),
#pragma ;
, ftelif
; .
" \ " ,
. . . 12 .
-
l;
, . (
.
3 17
318
- ??
.
# \ [] { } 1 -,
12 . 1 .
? ? .
. 2. .
- :
8 9 .
L , F L
. ,
.
- ;
2.6.
- , ,
signed
unsigned.
- unsigned char.
signed char
void
char
void*
; ,
,
, .
Rt!
319
++ ,
const
( 8.
2) .
" " , ,
" , unsigned ; ,
double" "
". . .
=+
, ;
, , .
+ -.
*.
sizeof, int ; ,
unsigned .
, size_ t ,
<stddef. h>.
(ptrdiff_t) .
7. 4. 8 7 . 7 .
&
register,
.
. 7 . 8 .
320
-
, ;
..7.7.
- ( (++)
,
. 7.3.2 ,
86.3 , 57 .
l .
- ,
, , .
,
, .
( ) .
extern
l .
All. 1. ,
. ( . )
1 ,
(\0- )
swi tch 1
' 21.43-45,226
-- (
1) 20, 55, 124, 238
- 49, 241
- 238-239
! 50, 238-239
!= . 18, 49, 243
9, 22, 45, 227
# 105.278
## 105,278
#def i 15,104.276
#def ine enum 46,175
#def ine 104
#def ine, 104
#else, #elif 107,281
#endif 107
#error 282
#if 107, 158, 279
#ifdef 107,281
#ifndef 107,281
#include 38, 103, 178, 279
#line 282
#pragrma 282
#undef105,202, 278
% n
() 49, 241
%1d 20
& 109, 238
&& 24, 49, 58, 243
&. : 57, 243
* 49, 241
* 110,238
, 73, 247
. 150, 235
.. . 182, 237
.h 38
1 11,49,241
?: 61, 246
\\ (. backslash) 9, 45
\ null ( , , ) 35, 45, 226
\ 45,226
\b (. backspace) 9,
45,226
\f _ (. formfeed), 45,226
\ _, 7, 17, 22. 43-45, 226, 291
\r (. carriage retur) 45,226
\t , 9, 12, 45,226
\v , 45,226
\ 43, 226
: 57, 243
_ 4 1 , 226,291
_FILE_ m 309
_ LINE_ 309
_fillbuf 209
_IOFBF, _IOLBF, _IONBF 294
1 : 57, 243
11 24, 49, 58, 246
- 58, 238-239
+ 49, 241
+ n n 238-239
++ (
1) 20, 55,1 24, 238
+= 59
< n 49, 242
n 58, 242
<= n n 49, 242
<assert.h> (. header) 308
<ctype.h> 51,301
<errno.h> 301
<float.h> 42,314
<liraits.h> 42,314
<locale.h> 291
<math. h> 52, 304
<setjmp.h> 309
<signal .h> 311
<stdarg.h> 182, 205, 309
<stddef .h> 121 , 158, 291
<stdio.h> , 18, 104-105, 119, 177-178,291
<stdio.h>, 207
<stdlib.h> 83, 166, 305
<string.h> 46, 124, 302
<time.h> 311
= n 19, 50, 246
== n 21, 49, 243
32 1
322
154,235
n 3,
n 3, 87,
, 93,
228
228
275
asin 305
asm 224
atan, atan2 305
atexit 308
atof 305
atof 83
atoi 305
atoi 51, 72, 8
atol 305
auto n n
249
, 3, 47, 99, 22
n
, n
241
32, 110,238
249
n, & 109, 238
294
(. null)
, \
200
getchar 202
20, 2
119, 232
(. null) 45
(. null), , \ 35, 45, 22
223, 27
(. null) n
45, 22
, 27
,
, n
105, 278
71, 104
7, 79, 93
n 187,291-292
13
, n
23
n n
117
28, 235
, n
54, 237
117
28, 237
n ,
, for ~;)
58, 175
n , &
57, 243
n , 1 57, 243
, void(npaa) 38,8,20,270
n ,
, n
n, 17,25 1
133-1 38
110,115,117-121, 137,
n, n
12,241
- 5, 98, 28
50, 232
98, 28
_n
229
n 2,
150, 253
49
n (),
n
57, 243
57, 243
234
a.out , 82
abort 306
abs 308
305
addpoint 152
addtree 15
afree 119
alloc 118
argc 133
argv 133, 190
ASCII 21, 43, 51, 27, 302
asctime 312
102,1 29
10, 20, 42,314
binsearch 9, 157, 1 1
bitcount 59
break 70, 7, 29
bsearch 308
19, 24, 1
151
, , \v 45, 22
164, 253
200
200
, 91
gmtime 312
goto 77, 29
, f
17, 177
/, 192, 301
178, 188, 200
,
41, 224
97 _
228, 275
11, 21 , 2,
15
()
103, 279
200
, 187, 206, 292
, 188, 199
, 187, 209, 292
, 187, 199, 202
, 187, 20, 292
, 204
, n 187, 199, 209, 292
,
/, ()
35, 235
, ()
()
18-19, 201,204
101,132, 156
( )
101,262
(),
9,
323
266
187
130
131, 23
50, 232
va_list, va_start, va_arg, va_end 182,205,297,309
void 109, 121, 140, 233
void 38, 8, 260, 270
void 35, 229, 233, 250
volatile, 229, 250
vprintf, vfprintf, vspr i tf
205, 297
()
void
, 93, 275
, 47, 95, 99, 22
7, 11, , 98
, 11
1, 20, 42, 314
162,239
121, 232
21 , 77
getbits 58
getc 188, 299
getc 207
getch 92
getchar, ubuffered 201
getchar, 202
getchar, 17, 177, 188, 299
getenv 308
getint 114
getline 33, 37, 81, 193
getop 91
gets 192, 299
gettoken 146
getword 10
if-else
, 28,
129,131,263
283
25-20
257
, 23
259
10, 47, 249-254
typedef 171 , 249, 265
union 172, 251
249
36, 270
25, 130,257
25 7
n 11 , 117, 257
150, 251
259-260
, 31 , 85, 235
38, 93, 249
, 176, 251
, 270-272
, , -- 20, 55, 124, 238
, , 1 11, 49, 241
, 11, 49
228, 273-275
93, 275
93, 275
78, 2, 275
, 273
, n 93, 273
1, 11 , 229
, ,>>
7,
70
58, 242
324
28,235
38, 273
27
249
28, 235
28, 81 , 270
, #udef
,
273
na 54, 230
(),
210
scanf, 184,297
19, 24, 1
, 19, 24, 1, 24
, 52, 24
, n , += 59
, n , = 19, 50, 246
, , 50, 59, 246
, 24
41 ,224
224
35, 45, 122
63, 105, 234, 237
, 163
, 144
day_of_year 130
defined 107, 281
del n 146
del 144
difftime 312
DIR, 212
dir.h 215
dirdcl 145
Dirent, 212
dirwalk 214
div 308
div_t, ldiv_t 308
,
d, 75 , 29
do-nothing 82
double 43,227
double, 11, 20, 42, 229, 250
double-float 54, 232
, n
111,234
,
46, 107,226-227, 25
25
227, 256
49,243
21, 49,243
229
61 , 97, 103, 166,219
43, 227
EBCDIC 51
echo, 134-135
EDOM304
else if-else
else-if 26, 67
end of file EOF
enum #define 46, 175
enum n 4,25
EOF 18, 177, 292
ERANGE 304
erro 301, 304
error 205
errors, / 192, 301
exit 190, 30
EXIT_FAILURE, EXIT_SUCCESS 306
305
expansion, 278
extern
3, 38, 93, 249
189,192
291
,
n,
,
38, 96
235
()
166,217-221
, n,,
73, 247
22, 163
17, 177
302
, 52,228
, 52, 228
52-54, 208, 226
21,43, 22
, 43
, 226
-, 26,50, 230
( ), 184, 194,
297,302
/
, 27
, ,==
, ,
25
, , EBCDIC
, ,
194, 301
238
, , ,
n n 52, 230
224
goto 78
union () 218
178
234-247
235
( )
131,263
101,132,262
119,162
47, 99, 262
150,262
262
156
234, 311
278
if-else , 268, 283
if-else 21 ,24,65,268
inode 210
instali 170
int type 1, 42, 250
isalnum 160,302
isalpha 160, 194, 302
iscntrl 302
isdigit 194,302
lseek 205
isgraph 302
islower 194,302
ISO 276
isprint 302
ispunct 302
isspace 160, 194, 302
isupper 194,302
isxdigit 302
itoa 76
jump, 269
249
, automatic
36,228
extern
n 36, 38, 93, 249
n, register
97, 249
n, static 36, 97, 228
n, static n
97, 249
, 249
,
n,
101,
251
, n , ++
79-80, 88, 90
11 , 65
, 2
176, 253
162, 1,
, printf,
229
2-270
174,195,217, 233
17, 178, 190, 200
, 9, 21, 43-45,226,276
, , \ 43, 226
, 45, 226
(n)
325
250
, n
250
20, 55, 124,
224
326
, 15
133-1 38
28
217-221
179
249
, () 1,
10,223-224, 27
82
79, 93, 273
, , - 58, 238-239
( ) 105, 278
( )
( ), , %
45,105,227
241
,
,
43, 22
43, 224
, ( . backslash), \\
9, 45
302
103, 27-278
(a.lvalue)
230
, , <<
58, 242
138
273
223
21
, 27
, n,
main
main, return 29, 192
makepoint 152
malloc 18, 195, 30
malloc 219
memchr 304
memcmp 304
memcpy 304
memmove 304
memset 304
mktime 312
modf 305
month_day 130
month_name 132
morecore 220
224
, ,!
, ,
21
50, 238-239
OR, , ! ! 24, 49, 58, 24
, 52
, , 5.& 24, 49, 58, 243
, 291
labs 308
ldexp 305
ldiv 308
localtime 312
log,log 10 305
long double, 43, 227
long double, 42,227
long, 43,22
long, 11, 20, 42, 227, 250
LONG_MAX, LONG_MIN
longjmp 309
lookup 170
lower 51
ls 210
49,
49, 241
45,9, 107,247
131,
259
278
43, 22
249
103,275-282
104
54, 237
, 52, 230
() 3, 86, 228
() ,
f3,270
() ,
of38,273
()
270-271
41,
( ) ,
224
()
() 8,
97
224, 228,
250, 275
,
33, 37
scientific) 43, 8
getchar 201
200
117
, , != 18,49,243
251
85
119-1 21, 12,
(.
241
327
n 49, 243
n n 57, 242
52,228
n n
n,
241
41
57, 243
n,
n,
n,n
, n (n
154-155, 234
n,
241
n, n (n )
n, 63
257
25, 130, 257
, 25, 114, 235, 259
, 101 , 132, 262
n n,
131,263
121
174
n 200
n 202
, n
54,230
11,49,241
#undef
, n
129, 259
116,234
, n
131,259
n n
235
, ( . carriage return), \r 45, 226
_ (. formfeed), , \f 45, 226
_ 223, 276
_, , \n 7, 17, 22,43-45, 226, 291
, n n , 123
n
52
50, 52
138NULL, 119
numcmp 141
228, 230
() ( . pattern), n f
79,81 , 135-137
87
- 49, 241
121, 162, 232
77,266
69,266
, default 69, 266
, 78, 266, 275
52, 228
77, 266
n 42,250
, 235
43
, ... 43, 226
n ,+ 49,241
n of 62, 234
n 50, 59, 246
,
250
250
O_RDONLY. O_RDWR, O_WRONLY 202
opendir 215
... 43, 226
98, 116,236
n,
28, 235
napcep, -n 144
n 144
, 82
n 129,259
24
n 26, 67
n () 31
31 , 111 ,236
91
228, 273-275
, 228, 275
, 86, 224, 228, 250, 275
( ), 269
n , , >= 49, 242
, n, > 49, 242
, , _ 41 , 224, 291
n, 117
125, 139
, 138
n, 138
, n 126, 139
11
n 187, 206,292
n 160
138, 172, 235
328
li
, void
, - 2,50, 230
, ( )
234
110, 117,257
, 119, 12
, 1, 232, 241
114,1 1,259
, 120
, 125
, 120, 12, 232
, 119, 12, 219, 225
110, 115, 117-120, 137,
1 2, 241
,
,
12,
121, 232
119-121,
241
-,
231-233, 241
87
, ,
, ,
, -
232-234, 241
54, 230
, - 54
, - 233, 241
, - 13, 230
, 54, 232-234, 241
, 54, 16, 195, 232, 241,
263
, 103, 275-282
, defied 107,281
, # 105, 278
n , ## 105, 278
, _FILE_
309
, _LINE_ 309
, 282
++-- 55, 124
(. overflow) 49,234,304, 311
, -
n (. uderflow)
++--
57, 242
55, 123
, 187,291-292
, 17, 177, 291
45
204
234
ull
52, 232
117
, (.
, float-double
82
25, 70
n , 223
, 184, 194, 297, 302
, 275
, 223, 275
, 223, 270, 273
() 19, 2, 111 ,
154-155, 234
3, 43, 51 , 58, 172, 177, 179, 217
, 49, 130
, 50, 232
() 231-233
( ) 11, 234
166,232,241
retur 8, 270
15
18-19, 201,204
33, 37
( , .
126,139
234
(. retur) 8,
21
187
25, 70
()
21
270
13-15,17
52, 246
54, 232-234, 241
, double-float 54, 232
179
9-1 ,
18
11, 21 , 25, 47, 12, 223
n,
228
182,205,236,260,270,309
36,87,228
n, 32, 11 , 238
,
224
41 , 224
nn 29, 35, 54, 85, 140, 236
perror 301
90
pow 27, 305
power 28, 31
printd 102
printf 7, 12, 20, 179, 296
printf , 180, 2%
pintf , 14,180
ptlnreet 152
ptrdiff_t 121, 172, 242
push 90
putc 188,299
putc 207
putchar 17, 178, 188, 299
puts 192, 299
,
329
register
n 97, 249
remove 292
rename 292
return (n) main 29, 192
return, cao 28,35, 82, 86,270
return, n 86, 270
reverse 73
rewind 301
Richards, . 1
Ritchie, D. . xi
164,253
266
268
41
41 , 224
227
n 199
65, 98, 266, 270-272
, 236
n
249
n ,
auto 249
n,
-,
54, 230
/,
(n) n
250
struct
111 , 234
275
42,224
napcep 144
101,163,165,214, 237,269
276
249
256
union 256
250
50, 52
291
28, 38, 85, 237
, 47, 99, 262
( ) 27, 305
7, 22, 35, 45, 116, 122, 227
-,
101 , 262
,
227
330
, 234
,
, n
168
printf 180,296
printfpep 14,180
scanf 185, 298
45, 226
63
291
(, ) enumeration 256
(, ) union 256
r (, ) 150, 251
, 17,177,200
17, 177, 291
, 125, 139
, 9-1 ,
13-15, 17
, 17
43, 226
234
, 257
, 246, 250
n, n
251
85
n, n 250
, 250
n, 229
n, 265
n, 1, 11, 229
n, 263
n, 229
n 11, 17, 20, 65, 67
276
tll 166
tan 305
tanh 305
Thompson, . L. 1
time 312
time_t n 311
_294
, n
n,
scanf
printf
1, 42, 228
194, 301
, 259-260
, n 31, 85,235
, 235
, 138, 172, 235
, 234
, - 236
, - 29, 38, 85, 236
, static 97
28, 81 , 270
28, 233
, n, n, n,
238-239
+ 238-239
174
,
, ( , )
262
251
, n
n
223, 275
tmpfile 294
tmpnam 294
tolower 179, 194, 302
toupper 194, 302
treeprint 166
trim 77
typedef 171, 249, 265
types, 229
types, 1, 42, 228
types.h 21 3, 215
, n
331
?: 61, 246
107, 279
ULONG_MAX 306
undcl 147
ungetc 194, 299
ungetch 92
union, 172, 251
union, n 218
uion, 251
UNIX 199,210
unlink 205
unsigned char, n 42, 201
unsigned long 43,226
unsigned 43, 226
unsigned, 42, 59, 229, 250
259
41 , 224
235
, 235
n 29, 35, 54, 85, 140, 235
n 35, 235
fpos_t 301
fprintf 188, 294
fputc 299
fread 299
fabs 305
fclose 189, 292
fcntl.h 202
feof 192, 301
feof 207
ferror 192, 301
feror 207
ff\ush 292
fgetc 298
fgetpos 301
fgets 192, 299
fgets 193
FILE 187
filecopy 189
FILENAME 292
float, 43, 227
float, 1, 42, 229, 250
float-double, n 52, 232
floor 305
fmod 305
fopen 187,292
fopen 208
FOPEN_MAX 292
,
332
, \ 43,
, ...
226
43, 226
hash 169
hash 169
Hoare, . . R. 102
HUGE_VAL 304
178, 200
-, n 54
-n, n
-, n
t
233,241
13,230
13,43,226
while, for, do
creat n 202
CRLF 177, 291
ctime 312
150, 253
226
227
qsort 308
qrt 102, 129, 140
w
wchar_t n 226
while n for 15, 71
while, 11, 71 , 269
write n 200
writelines 127
1 .
.
,
. , ,
.
, ..
.
,
"
".
, .
.
ISBN 978-608-4535-48-5
9 786084 535485