.

Язык С

Язык: русский
Формат: реферат
Тип документа: Word Doc
117 19077
Скачать документ

ssCUE N

A.A. Ea?ieaai,

Ae.I. ?e/e.Aiiioaoeey.

sscue “C”(i?ieciineony “ne”) – yoi oieaa?naeueiue ycue i?ia?aiie?iaaiey,
aeey eioi?iai oa?aeoa?iu yeiiiie/iinoue au?aaeaiey, nia?aiaiiue iioie
oi?aaeaiey e no?oeoo?u aeaiiuo, aiaaoue iaai? iia?aoi?ia. sscue “C” ia
yaeyaony ie ycueii “i/aiue aunieiai o?iaiy”, ie “aieueoei” ycueii, e ia
i?aaeiacia/aaony aeey iaeioi?ie niaoeeaeueiie iaeanoe i?eiaiaiey. ii
ionoonoaea ia?aie/aiee e iauiinoue ycuea aeaeatho aai aieaa oaeiaiui e
yooaeoeaiui aeey iiiaeo caaea/, /ai ycuee, i?aaeiieiaeeoaeueii aieaa
iiuiua.

sscue “C”, ia?aiia/aeueii i?aaeiacia/aaoeeny aeey iaienaiey
iia?aoeeiiiie nenoaiu “UNIX” ia YAI DEC PDP-11, aue ?ac?aaioai e
?aaeeciaai ia yoie nenoaia Aeaiienii ?e/e. Iia?aoeeiiiay nenoaia,
eiiieeyoi? n ycuea “C” e ii nouanoao ana i?eeeaaeiua i?ia?aiiu nenoaiu
“UNIX” (aeeth/ay ana i?ia?aiiiia iaania/aiea, eniieueciaaiiia i?e
iiaeaioiaea yoie eieae) iaienaiu ia “C”. Eiiia?/aneea eiiieeyoi?u n
ycuea “C” nouanoaotho oaeaea ia iaeioi?uo ae?oaeo YAI, aeeth/ay IBM
SYSTEM/370, HONEYWELL 6000, INTERDATA 8/32. sscue “C”, iaeiaei, ia
naycai n eaeeie-eeai ii?aaeaeaiiuie aiia?aoiuie n?aaenoaaie eee
nenoaiaie, e ia iai eaaei ienaoue i?ia?aiiu, eioi?ua iiaeii i?iioneaoue
aac eciaiaiee ia ethaie YAI, eiathuae “C”-eiiieeyoi?.

Yoa eieaa i?aaeiacia/aia aeey oiai, /oiau iiii/ue /eoaoaeth iao/eoueny
i?ia?aiie?iaaoue ia ycuea “C”. Iia naea?aeeo o/aaiia aaaaeaiea, oeaeue
eioi?iai – iicaieeoue iiaui iieueciaaoaeyi ia/aoue i?ia?aiie?iaaoue eae
iiaeii auno?aa, ioaeaeueiua aeaau ii anai iniiaiui iniaaiiinoyi ycuea e
ni?aai/iia ?oeiaiaenoai. Iao/aiea iino?iaii a iniiaiii ia /oaiee,
iaienaiee e ?acai?a i?eia?ia, a ia aieie oi?ioee?iaea i?aaee. I?eia?u,
i?eaiaeeiua a eieaa, ii aieueoae /anoe yaeythony caeii/aiiuie ?aaeueiuie
i?ia?aiiaie, a ia ioaeaeueiuie o?aaiaioaie. Ana i?eia?u auee i?iaa?aiu
iaiin?aaenoaaiii n oaenoa eieae, aaea iie iaia/aoaiu a aeaea, i?eaiaeiii
aeey aaiaea a iaoeio. E?iia oeacaiee i oii, eae naeaeaoue eniieueciaaiea
ycuea aieaa yooaeoeaiui, iu oaeaea iuoaeenue, aaea yoi aiciiaeii,
i?ieeethno?e?iaaoue iieaciua aeai?eoiu e i?eioeeiu oi?ioaai noeey e
?acoiiie ?ac?aaioee.

Ianoiyuay eieaa ia yaeyaony aaiaeiui eo?nii a i?ia?aiie?iaaiea; iia
i?aaeiieaaaao ii?aaeaeaiiia ciaeiinoai n iniiaiuie iiiyoeyie
i?ia?aiie?iaaiey oaeeie eae ia?aiaiiua, iia?aoi?u i?enaaeaaiey, oeeeeu,
ooieoeee. Oai ia iaiaa e iiae/ie a i?ia?aiie?iaaiee aeieaeai ieacaoueny
a ninoiyiee /eoaoue iiae?yae e inaieoueny n ycueii, oioy i?e yoii auea
au iieaciie iiiiuue aieaa iiuoiiai eieeaae.

Ii iaoaio iiuoo , “C” iieacae naay i?eyoiui, au?aceoaeueiui e
?aciinoi?iiiei ycueii ia oe?ieii iiiaeanoaa ?aciiia?aciuo i?ia?aii. Aai
eaaei auo/eoue , e ii ia oa?yao naieo ea/anoa n ?inoii iiuoa
i?ia?aiienoa. Iu iaaeaainy , /oi yoa eieaa iiiiaeao aai oi?ioi aai
eniieueciaaoue.

Aaeoi/eaay e?eoeea e i?aaeeiaeaiey iiiaeo iaoeo ae?ocae e eieeaa i/aiue
iiiai aeiaaaeee eae aeey naiie eieae, oae e aeey iaoaai oaeiaieuenoaey
i?e aa iaienaiee. A /anoiinoe, Iaee Aeaine, Aeaeei Aeth, Noueth
Oaeueaeiai, Aeioa Iae-Ee?ie, Aeee ?oi, Aia ?icei e Ea??e ?inea?
ouaoaeueii i?i/eoaee iiiaeanoai aa?eaioia. Iu oaeaea iaycaiu Yeth Aoi,
Noeao Ai?io, Aeyao Aeai?aeo, *aeo Oyeath, Aeaaae Oyeae, Ia?eiio Oa??eno,
?eeo Oieoo, Noeao Aeaeiiniio, Aeaeiio Iaoath, Aiao Ieooeo, ?aeueoo
Iuetha, Ieoa?o Iaeueniio, Yeeeioo Ieiniio, Aeeeo Ieaaa?o, Aeaea??e
Nieaaeo, Eaio Oiiiniio e Ieoa?o Aaeiaa?aa?o ca iieaciua caia/aiey ia
?acee/iuo yoaiao e Iaeeo Eineo e Aeaei Inaiia ca iaioeaieioth iiiiuue
i?e ia/aoaiee eieae. A?aeai A. Ea?ieaai Aeaiien I. ?e/e

Niaea?aeaiea.

Aiiioaoeey

0.1. Aaaaeaiea

1. O/aaiia aaaaeaiea

1.1. Ia/eiaai

1.2. Ia?aiaiiua e a?eoiaoeea

1.3. Iia?aoi? FOR

1.4. Neiaiee/aneea eiinoaiou

1.5. Iaai? iieaciuo i?ia?aii

1.5.1. Aaiae e auaiae neiaieia

1.5.2. Eiie?iaaiea oaeea

1.5.3. Iiaen/ao neiaieia

1.5.4. Iiaen/ao no?ie

1.5.5. Iiaen/ao neia

1.6. Ianneau

1.7. Ooieoeee

1.8. A?aoiaiou – aucia ii cia/aieth

1.9. Ianneau neiaieia

1.10. Iaeanoue aeaenoaey: aiaoiea ia?aiaiiua

1.11. ?acthia

2. Oeiu, iia?aoeee e au?aaeaiey

2.1. Eiaia ia?aiaiiuo

2.2. Oeiu e ?acia?u aeaiiuo

2.3. Eiinoaiou

2.3.1. Neiaieueiay eiinoaioa

2.3.2. Eiinoaioiia au?aaeaiea

2.3.3. No?i/iay eiinoaioa

2.4. Iienaiey

2.5. A?eoiaoe/aneea iia?aoeee

2.6. Iia?aoeee ioiioaiey e eiae/aneea iia?aoeee

2.7. I?aia?aciaaiea oeiia

2.8. Iia?aoeee oaaee/aiey e oiaiueoaiey

2.9. Iiaeoiaua eiae/aneea iia?aoeee

2.10. Iia?aoeee e au?aaeaiey i?enaaeaaiey

2.11. Oneiaiua au?aaeaiey

2.12. Noa?oeinoai e ii?yaeie au/eneaiey

3. Iioie oi?aaeaiey

3.1. Iia?aoi?u e aeiee

3.2. IF – ELSE

3.3. ELSE – IF

3.4. Ia?aeeth/aoaeue

3.5. Oeeeeu – WHILE e FOR

3.6. Oeeee DO – WHILE

3.7. Iia?aoi? BREAK

3.8. Iia?aoi? CONTINUE

3.9. Iia?aoi? GOTO e iaoee

4. Ooieoeee e no?oeoo?a i?ia?aii

4.1. Iniiaiua naaaeaiey

4.2. Ooieoeee, aica?auathuea iaoeaeua cia/aiey

4.3. Aua ia a?aoiaioao ooieoeee

4.4. Aiaoiea ia?aiaiiua

4.5. I?aaeea, ii?aaeaeythuea iaeanoue aeaenoaey

4.5.1. Iaeanoue aeaenoaey

4.6. Noaoe/aneea ia?aiaiiua

4.7. ?aaeno?iaua ia?aiaiiua

4.8. Aei/iay no?oeoo?a

4.9. Eieoeeaeecaoeey

4.10. ?aeo?ney

4.11. I?ai?ioeanni? ycuea “C”

4.11.1. Aeeth/aiea oaeeia

4.11.2. Mae?iiiaenoaiiaea

5. Oeacaoaee e ianneau

5.1. Oeacaoaee e aae?ana

5.2. Oeacaoaee e a?aoiaiou ooieoeee

5.3. oeacaoaee e ianneau

5.4. Aae?aniay a?eoiaoeea

5.5. oeacaoaee neiaieia e ooieoeee

5.6. Oeacaoaee – ia oeaeua

5.7. Iiiaiia?iua ianneau

5.8. Ianneau oeacaoaeae; oeacaoaee oeacaoaeae

5.9. Eieoeeaeecaoeey ianneaia oeacaoaeae

5.10. Oeacaoaee e iiiaiia?iua ianneau

5.11. Eiiaiaeiay no?iea a?aoiaioia

5.12. Oeacaoaee ia ooieoeee

6. No?oeoo?u

6.1. Iniiaiua naaaeaiey

6.2. No?oeoo?u e ooieoeee

6.3. Ianneau no?oeoo?

6.4. Oeacaoaee ia no?oeoo?u

6.5. No?oeoo?u, nnueathueany ia naay

6.6. Iiene a oaaeeoea

6.7. Iiey

6.8. Iauaaeeiaiey

6.9. Ii?aaeaeaiea oeia

7. Aaiae e auaiae

7.1. Ia?auaiea e noaiaea?oiie aeaeeioaea

7.2. Noaiaea?oiue aaiae e auaiae – ooieoeee GETCHAR e PUTCHAR

7.3. Oi?iaoiue auaiae – ooieoeey PRINTF

7.4. Oi?iaoiue aaiae – ooieoeey SCANF

7.5. Oi?iaoiia i?aia?aciaaiea a iaiyoe

7.6. Aeinooi e oaeeai

7.7. Ia?aaioea ioeaie – STDERR e EXIT

7.8. Aaiae e auaiae no?ie

7.9. Ianeieueei ?aciiia?aciuo ooieoeee

7.9.1. I?iaa?ea aeaea neiaieia e i?aia?aciaaiey

7.9.2. Ooieoeey UNGETC

7.9.3. Ia?auaiea e nenoaia

7.9.4. Oi?aaeaiea iaiyoueth

8. Eioa?oaen nenoaiu UNIX

8.1. Aeane?eioi?u oaeeia

8.2. Ieceio?iaiaaue aaiae/auaiae – iia?aoi?u READ e WRITE

8.3. Ioe?uoea, nicaeaiea, cae?uoea e ?anuaieaiea (UNLINK)

8.4. I?iecaieueiue aeinooi – SEEK e LSEEK

8.5. I?eia? – ?aaeecaoeey ooieoeee FOPEN e GETC

8.6. I?eia? – ?ania/aoea ni?aai/ieeia

8.7. I?eia? – ?ani?aaeaeeoaeue iaiyoe

9. I?eeiaeaiea a: ni?aai/iia ?oeiaiaenoai ii ycueo ‘C’.

9.1. Aaaaeaiea

10. Eaene/aneea niaeaoaiey

10.1. Eiiiaioa?ee

10.2. Eaeaioeoeeaoi?u (eiaia)

10.3. Eeth/aaua neiaa

10.4. Eiinoaiou

10.4.1. Oeaeua eiinoaiou

10.4.2. ssaiua aeeeiiua eiinoaiou

10.4.3. Neiaieueiua eiinoaiou

10.4.4. Ieaaathuea eiinoaiou

10.5. No?iee

10.6. Oa?aeoa?enoeee aiia?aoiuo n?aaenoa

11. Neioaene/aneay iioaoeey

12. *oi a eiaie oaaa iiai?

13. Iauaeou e L-cia/aiey

14. I?aia?aciaaiey

14.1. Neiaieu e oeaeua

14.2. Oeiu FLOAT e DOUBLE

14.3. Ieaaathuea e oeaei/eneaiiua aaee/eiu

14.4. Oeacaoaee e oeaeua

14.5. Oeaeia aac ciaea

14.6. A?eoiaoe/aneea i?aia?aciaaiey

15. Au?aaeaiey

15.1. Ia?ae/iua au?aaeaiey

15.2. Oia?iua iia?aoeee

15.3. Ioeueoeieeeaoeaiua iia?aoeee

15.4. Aaeaeeoeaiua iia?aoeee

15.5. Iia?aoeee naeaeaa

15.6. Iia?aoeee ioiioaiey

15.7. Iia?aoeee ?aaainoaa

15.8. Iiaeoiaay iia?aoeey ‘e’

15.9. Iiaeoiaay iia?aoeey eneeth/athuaai ‘eee’

15.10. Iiaeoiaay iia?aoeey aeeth/athuaai ‘eee’

15.11. Eiae/aneay iia?aoeey ‘e’

15.12. Iia?aoeey eiae/aneiai ‘eee’

15.13. Oneiaiay iia?aoeey

15.14. Iia?aoeey i?enaaeaaiey

15.15. Iia?aoeey caiyoay

16. Iienaiey

16.1. Niaoeeoeeaoi?u eeanna iaiyoe

16.2. Niaoeeoeeaoi?u oeia

16.3. Iienaoaee

16.4. Niune iienaoaeae

16.5. Iienaiea no?oeoo? e iauaaeeiaiee

16.6. Eieoeeaeecaoeey

16.7. Eiaia oeiia

16.8. TYPEDEF

17. Iia?aoi?u

17.1. Iia?aoi?iia au?aaeaiea

17.2. Ninoaaiie iia?aoi? (eee aeie)

17.3. Oneiaiua iia?aoi?u

17.4. Iia?aoi? WHILE

17.5. Iia?aoi? DO

17.6. Iia?aoi? FOR

17.7. Iia?aoi? SWITCH

17.8. Iia?aoi? BREAK

17.9. Iia?aoi? CONTINUE

17.10. Iia?aoi? aica?aoa

17.11. Iia?aoi? GOTO

17.12. Iiia/aiiue iia?aoi?

17.13. Ionoie iia?aoi?

18. Aiaoiea ii?aaeaeaiey

18.1. Aiaoiaa ii?aaeaeaiea ooieoeee

18.2. Aiaoiea ii?aaeaeaiey aeaiiuo

19. I?aaeea, ii?aaeaeythuea iaeanoue aeaenoaey

19.1. Eaene/aneay iaeanoue aeaenoaey

19.2. Iaeanoue aeaenoaey aiaoieo eaeaioeoeeaoi?ia

20. No?iee oi?aaeaiey eiiieeyoi?ii

20.1. Caiaia eaenai

20.2. Aeeth/aiea oaeeia

20.3. Oneiaiay eiiieeyoeey

21. Iayaiua iienaiey

22. Niiaa i oeiao

22.1. No?oeoo?u e iauaaeeiaiey

22.2. Ooieoeee

22.3. Ianneau, oeacaoaee e eiaeaenaoeey

22.4. ssaiua i?aia?aciaaiey oeacaoaeae

23. Eiinoaioiua au?aaeaiey

24. Niia?aaeaiey i ia?aiineiinoe

25. Aiao?iieciu

26. Naiaeea neioaene/aneeo i?aaee

26.1. Au?aaeaiey

26.2. Iienaiey

26.3. Iia?aoi?u

26.4. Aiaoiea ii?aaeaeaiey

26.5. I?ai?ioeanni?

27. I?enaaeaaiea no?oeoo?u

28. Oei ia?a/eneaiey

29. Oaaeeoea ecia?aaeaiee iaia/aoiuo neiaieia ycuea “C”.

0.1. Aaaaeaiea.

sscue “C” yaeyaony oieaa?naeueiui ycueii i?ia?aiie?iaaiey. Ii oanii
naycai n iia?aoeeiiiie nenoaiie “UNIX” , oae eae aue ?acaeo ia yoie
nenoaia e oae eae “UNIX” e aa i?ia?aiiiia iaania/aiea iaienaii ia “C”.
Nai ycue , iaeiaei, ia

naycai n eaeie-eeai iaeiie iia?aoeeiiiie nenoaiie eee iaoeiie;

e oioy aai iacuaatho ycueii nenoaiiiai i?ia?aiie?iaaiey, oae

eae ii oaeiaai aeey iaienaiey iia?aoeeiiiuo nenoai, ii n ?aaiui

oniaoii eniieueciaaeny i?e iaienaiee aieueoeo au/eneeoaeueiuo

i?ia?aii, i?ia?aii aeey ia?aaioee oaenoia e aac aeaiiuo.

sscue “C” – yoi ycue ioiineoaeueii “ieceiai o?iaiy”. A

oaeie oa?aeoa?enoeea iao ie/aai inei?aeoaeueiiai; yoi i?inoi

icia/aao, /oi “C” eiaao aeaei n iauaeoaie oiai aea aeaea, /oi e

aieueoeinoai YAI, a eiaiii, n neiaieaie, /eneaie e aae?anaie.

Iie iiaoo iauaaeeiyoueny e ia?anueaoueny iin?aaenoaii iau/iuo

a?eoiaoe/aneeo e eiae/aneeo iia?aoeee, inouanoaeyaiuo ?aaeue-

iuie YAI.

A ycuea “C” ionoonoaotho iia?aoeee, eiathuea aeaei iaiin-

?aaenoaaiii n ninoaaiuie iauaeoaie, oaeeie eae no?iee neiai-

eia, iiiaeanoaa, nienee eee n ianneaaie, ?anniao?eaaaiuie eae

oeaeia. Caeanue, iai?eia?, iao ieeaeiai aiaeiaa iia?aoeeyi PL/1,

iia?e?othuei n oeaeuie ianneaaie e no?ieaie. sscue ia i?aaein-

oaaeyao ieeaeeo ae?oaeo aiciiaeiinoae ?ani?aaeaeaiey iaiyoe,

e?iia noaoe/aneiai ii?aaeaeaiey e iaoaiecia noaeia, iaania/e-

aaaiiai eieaeueiuie ia?aiaiiuo ooieoeee; caeanue iao ie

“eo/”(HEAP), ie “nai?ee ioni?a”, eae yoi i?aaeoniao?eaaaony a

AEAIEA-68. Iaeiiaoe, nai ii naaa “C” ia iaania/eaaao ieeaeeo

aiciiaeiinoae aaiaea-auaiaea: caeanue iao iia?aoi?ia READ eee

WRITE e ieeaeeo ano?iaiiuo iaoiaeia aeinooia e oaeeai. Ana yoe

iaoaieciu aunieiai o?iaiy aeieaeiu iaania/eaaoueny yaii aucuaa-

aiuie ooieoeeyie.

Aiaeiae/ii, ycue “C” i?aaeeaaaao oieueei i?inoua, iinea-

aeiaaoaeueiua eiino?oeoeee iioieia oi?aaeaiey: i?iaa?ee, oeeeeu,

a?oiie?iaaiea e iiaei?ia?aiiu, ii ia ioeueoei?ia?aiie?iaaiea,

ia?aeeaeueiua iia?aoeee, neio?iiecaoeeth eee nii?ia?aiiu.

Oioy ionoonoaea iaeioi?uo ec yoeo n?aaenoa iiaeao auaey-

aeaoue eae oae?o/athuay iaiieiioeaiiinoue (“auoiaeeo, /oi y aeieaeai

ia?auaoueny e ooieoeee, /oiau n?aaieoue aeaa no?iee neiaieia

?!”), ii oaea?aeaiea ycuea a ne?iiiuo ?acia?ao aeaao ?aaeueiua

i?aeiouanoaa. Oae eae “C” ioiineoaeueii iae, ii ia o?aaoao

iiiai ianoa aeey naiaai iienaiey e iiaeao auoue auno?i auo/ai.

Eiiieeyoi? n “C” iiaeao auoue i?inoui e eiiiaeoiui. E?iia oi-

ai, eiiieeyoi?u eaaei ieooony; i?e eniieueciaaiee nia?aiaiiie

oaoiieiaee iiaeii iaeeaeaoue iaienaiey eiiieeyoi?a aeey iiaie YAI

ca ia?o ianyoeaa e i?e yoii ieaaeaony, /oi 80 i?ioeaioia i?ia-

?aiiu iiaiai eiiieeyoi?a aoaeao iauae n i?ia?aiiie aeey oaea

nouanoaothueo eiiieeyoi?ia. Yoi iaania/eaaao aunieoth noaiaiue

iiaeeueiinoe ycuea. Iineieueeo oeiu aeaiiuo e nooeoo?u oi?aaea-

iey, eiathueany a “C”, iaiin?aaenoaaiii iiaeaea?aeeaathony aieue-

oeinoaii nouanoaothueo YAI, aeaeeioaea, iaiaoiaeeiay ai a?aiy

i?iaiia eciee?iaaiiuo i?ia?aii, ieacuaaaony i/aiue iaeaiueeie.

Ia PDP -11, iai?eia?, iia niaea?aeeo oieueei i?ia?aiiu aeey

32-aeoiaiai oiiiaeaiey e aeaeaiey e aeey auiieiaiey i?ia?aii

aaiaea e auaiaea iineaaeiaaoaeueiinoae. Eiia/ii, eaaeaeay ?aaeeca-

oeey iaania/eaaao en/a?iuaathuoth, niaianoeioth aeaeeioaeo ooie-

oeee aeey auiieiaiey iia?aoeee aaiaea-auaiaea, ia?aaioee no?ie e

?ani?aaeaeaiey iaiyoe, ii oae eae ia?auaiea e iei inouanoaey-

aony oieueei yaii, iiaeii , anee iaiaoiaeeii, ecaaaeaoue eo auci-

aa; yoe ooieoeee iiaoo auoue eiiiaeoii iaienaiu ia naiii “C”.

· 8 –

Iiyoue aea ec-ca oiai , /oi ycue “C” io?aaeaao aiciiaeiinoe

nia?aiaiiuo eiiiuethoa?ia, i?ia?aiiu ia “C” ieacuaathony aeinoa-

oi/ii yooaeoeaiuie, oae /oi ia aicieeaao iiaoaeaeaiey ienaoue

aianoi yoiai i?ia?aiiu ia ycuea annaiaea?a. Iaeaieaa oaaaee-

oaeueiui i?eia?ii yoiai yaeyaony naia iia?aoeeiiiay nenoaia

“UNIX”, eioi?ay ii/oe iieiinoueth iaienaia ia “C”. Ec 13000

no?ie i?ia?aiiu nenoaiu oieueei ieiei 800 no?ie naiiai iecei-

ai o?iaiy iaienaiu ia annaiaea?a. E?iia oiai, ii nouanoao

ana i?eeeaaeiia i?ia?aiiiia iaania/aiea nenoaiu “UNIX” iaie-

naii ia “C”; iiaeaaeythuaa aieueoeinoai iieueciaaoaeae nenoaiu

“UNIX”(aeeth/ay iaeiiai ec aaoi?ia yoie eieae) aeaaea ia ciaao

ycuea annaiaea?a PDP-11.

Oioy “C” niioaaonoaoao aiciiaeiinoyi iiiaeo YAI, ii ia

caaeneo io eaeie-eeai eiie?aoiie a?oeoaeoo?u iaoeiu e a neeo

yoiai aac iniauo oneeee iicaieyao ienaoue “ia?aiineiua” i?ia-

?aiiu, o.a. i?ia?aiiu, eioi?ua iiaeii i?iioneaoue aac eciaia-

iee ia ?acee/iuo aiia?aoiuo n?aaenoaao. A iaoeo e?oaao noae

oaea o?aaeeoeeae ia?aiin i?ia?aiiiiai iaania/aiey, ?ac?aaioai-

iiai ia nenoaia “UNIX”, ia nenoaiu YAI: HONEYWELL, IBM e

INTERDATA. Oaeoe/anee eiiieeyoi?u n “C” e i?ia?aiiiia iaan-

ia/aiea ai a?aiy i?iaiia i?ia?aii ia yoeo /aou?ao nenoaiao,

ii-aeaeeiiio, ai?acaei aieaa niaianoeiu, /ai noaiaea?oiua aa?-

nee oi?o?aia aia?eeaineiai iaoeeiiaeueiiai einoeoooa noaiaea?-

oia (ANSI). Naia iia?aoeeiiiay nenoaia “UNIX” oaia?ue ?aaioaao

eae ia PDP-11, oae e ia INTERDATA 8/32. Ca eneeth/aieai i?ia-

?aii, eioi?ua iaecaaaeii ieacuaathony a iaeioi?ie noaiaie ia-

oeiii-caaeneiuie, oaeeo eae eiiieeyoi?, annaiaea? e ioeaae-

/ee. Iaienaiiia ia ycuea “C” i?ia?aiiiia iaania/aiea eaeai-

oe/ii ia iaaeo iaoeiao. Aioo?e naiie iia?aoeeiiiie nenoaiu

7000 no?ie i?ia?aiiu, eneeth/ay iaoaiaoe/aneia iaania/aiea

ycuea annaiaea?a YAI e oi?aaeaiey iia?aoeeyie aaiaea-auaiaea,

niaiaaeatho ia 95 i?ioeaioia.

I?ia?aiienoai, ciaeiiui n ae?oaeie ycueaie, aeey n?aaia-

iey e i?ioeaiiinoaaeaiey iiaeao ieacaoueny iieaciui oiiieiaiea

ianeieueeeo enoi?e/aneeo, oaoie/aneeo e oeeinioneeo aniaeoia

“C”.

Iiiaea ec iaeaieaa aaaeiuo eaeae “C” i?ienoiaeyo io ai?ac-

aei aieaa noa?iai, ii ana aua aiieia aeeciaiiiai ycuea BCPL ,

?ac?aaioaiiiai Ia?oeiii ?e/a?aenii. Einaaiii ycue BCPL ieacae

aeeyiea ia “C” /a?ac ycue “B”, iaienaiiue Eaiii Oiiiniiii a

1970 aiaeo aeey ia?aie iia?aoeeiiiie nenoaiu “UNIX” ia YAI

PDP-7.

Oioy ycue “C” eiaao ianeieueei iaueo n BCPL oa?aeoa?iuo

iniaaiiinoae, ii ieeiei ia?acii ia yaeyaony aeeaeaeoii iin-

eaaeiaai. E BCPL e “B” – “aacoeiiua” ycuee; aaeeinoaaiiui ae-

aeii aeaiiuo aeey ieo yaeythony iaoeiiia neiai, a aeinooi e ae?o-

aei iauaeoai ?aaeecoaony niaoeeaeueiuie iia?aoi?aie eee ia?a-

uaieai e ooieoeeyi. A ycuea “C” iauaeoaie iniiaiuo oeiia aeai-

iuo yaeythony neiaieu, oeaeua /enea ianeieueeeo ?acia?ia e /en-

ea n ieaaathuae oi/eie. E?iia oiai, eiaaony ea?a?oey i?iec-

aiaeiuo oeiia aeaiiuo, nicaeaaaaiuo oeacaoaeyie, ianneaaie,

no?oeoo?aie, iauaaeeiaieyie e ooieoeeyie.

· 9 –

sscue “C” aeeth/aao iniiaiua eiino?oeoeee iioiea oi?aaea-

iey, o?aaoaiua aeey oi?ioi no?oeooe?iaaiiuo i?ia?aii: a?oiie-

?iaaiea iia?aoi?ia, i?eiyoea ?aoaiee (IF), oeeeeu n i?iaa?eie

caaa?oaiey a ia/aea (WHILE, FOR) eee a eiioea (DO) e auai?

iaeiiai ec iiiaeanoaa aiciiaeiuo aa?eaioia (SWITCH). (Ana yoe

aiciiaeiinoe iaania/eaaeenue e a BCPL, oioy e i?e ianeieueei

ioee/iii neioaenena; yoio ycue i?aae/oanoaiaae ianooieaooth

/a?ac ianeieueei eao iiaeo ia no?oeoo?iia i?ia?aiie?iaaiea).

A ycuea “C” eiathony oeacaoaee e aiciiaeiinoue aae?aniie

a?eoiaoeee. A?aoiaiou ia?aaeathony ooieoeeyi iin?aaenoaii eiie-

?iaaiey cia/aiey a?aoiaioa , e aucaaiiay ooieoeey ia iiaeao

eciaieoue oaeoe/aneee a?aoiaio a aucuaathuae i?ia?aiia. Anee

aeaeaoaeueii aeiaeoueny “auciaa ii nnueea”, iiaeii iayaii ia?a-

aeaoue oeacaoaeue, e ooieoeey niiaeao eciaieoue iauaeo, ia eioi?ue

yoio oeacaoaeue oeacuaaao. Eiaia ianneaia ia?aaeathony oeacaie-

ai ia/aea ianneaia, oae /oi a?aoiaiou oeia ianneaia yooae-

oeaii aucuaathony ii nnueea.

E ethaie ooieoeee iiaeii ia?auaoueny ?aeo?neaii, e aa ei-

eaeueiua ia?aiaiiua iau/ii “aaoiiaoe/aneea”, o.a. Nicaeathony

caiiai i?e eaaeaeii ia?auaiee. Iienaiea iaeiie ooieoeee ia iiaeao

niaea?aeaoueny aioo?e ae?oaie, ii ia?aiaiiua iiaoo iienuaaoueny a

niioaaonoaee n iau/iie aei/iie no?oeoo?ie. Ooieoeee a “C” –

i?ia?aiia iiaoo o?ainee?iaaoueny ioaeaeueii. ia?aiaiiua ii io-

iioaieth e ooieoeee iiaoo auoue aioo?aiieie, aiaoieie, ii ec-

aanoiuie oieueei a i?aaeaeao iaeiiai enoiaeiiai oaeea, eee iie-

iinoueth aeiaaeueiuie. Aioo?aiiea ia?aiaiiua iiaoo auoue aaoiia-

oe/aneeie eee noaoe/aneeie. Aaoiiaoe/aneea ia?aiaiiua aeey

aieueoae yooaeoeaiinoe iiaeii iiiauaoue a ?aaeno?u, ii iauyaea-

iea ?aaeno?a yaeyaony oieueei oeacaieai aeey eiiieeyoi?a e ie-

eae ia naycaii n eiie?aoiuie iaoeiiuie ?aaeno?aie.

sscue “C” ia yaeyaony ycueii ni no?iaeie oeiaie a niunea

ianeaey eee aeaiea 68. Ii n?aaieoaeueii nienoiaeeoaeai e i?a-

ia?aciaaieth aeaiiuo, oioy e ia aoaeao aaoiiaoe/anee i?aia?aci-

auaaoue oeiu aeaiiuo n aoeiie iai?eioaeaeaiiinoueth ycuea PL/1.

Nouanoaothuea eiiieeyoi?u ia i?aaeoniao?eaatho ieeaeie i?iaa?ee

ai a?aiy auiieiaiey i?ia?aiiu eiaeaenia ianneaia, oeiia a?ao-

iaioia e o.ae.

A oao neooaoeeyo, eiaaea aeaeaoaeueia no?iaay i?iaa?ea oe-

iia, eniieuecoaony niaoeeaeueiay aa?ney eiiieeyoi?a. Yoa i?ia-

?aiia iacuaaaony LINT i/aaeaeii iioiio, iia auae?aao eoni/ee

iooa ec aaoae i?ia?aiiu. I?ia?aiia LINT ia aaia?e?oao iaoei-

iiai eiaea, a aeaeaao i/aiue no?iaoth i?iaa?eo anao oao noi?ii

i?ia?aiiu, eioi?ua iiaeii i?ieiio?iee?iaaoue ai a?aiy eiiieey-

oeee e caa?ocee. Iia ii?aaeaeyao ianiioaaonoaea oeiia, iania-

ianoeiinoue a?aoiaioia, iaeniieueciaaiiua eee i/aaeaeiui ia?a-

cii iaeieoeeaeece?iaaiiua ia?aiaiiua, iioaioeeaeueiua o?oaeiinoe

ia?aiineiinoe e o.ae. Aeey i?ia?aii,eioi?ua aeaaiiieo/ii i?i-

oiaeyo /a?ac LINT, aa?aioe?oaony ionoonoaea ioeaie oeia i?e-

ia?ii n oie aea iieiioie, eae e aeey i?ia?aii, iaienaiiuo,

iai?eia?, ia AEAIEA-68. Ae?oaea aiciiaeiinoe i?ia?aiiu LINT

aoaeoo ioia/aiu, eiaaea i?aaenoaaeony niioaaonoaothuee neo/ae.

· 10 –

Iaeiiaoe, ycue “C”, iiaeiaii ethaiio ae?oaiio ycueo, eiaao

naie iaaeinoaoee. Iaeioi?ua iia?aoeee eiatho iaoaea/iia noa?oei-

noai; iaeioi?ua ?acaeaeu neioaenena iiaee au auoue eo/oa; no-

oanoaoao ianeieueei aa?nee ycuea, ioee/athueony iaaieueoeie aea-

oaeyie. Oai ia iaiaa ycue “C” ca?aeiiaiaeiaae naay eae eneeth-

/eoaeueii yooaeoeaiue e au?aceoaeueiue ycue aeey oe?ieiai ?ac-

iiia?acey i?eiaiaiee i?ia?aiie?iaaiey.

Niaea?aeaiea eieae i?aaieciaaii neaaeothuei ia?acii. Aeaaa

1 yaeyaony o/aaiui aaaaeaieai a oeaio?aeueioth /anoue ycuea “C”.

Oeaeue – iicaieeoue /eoaoaeth noa?oiaaoue oae auno?i,eae oieueei

aiciiaeii, oae eae iu oaa?aei oaaaeaeaiu, /oi aaeeinoaaiiue nii-

nia eco/eoue iiaue ycue – ienaoue ia iai i?ia?aiiu. I?e yoii ,

iaeiaei, i?aaeiieaaaaony ?aai/aa aeaaeaiea iniiaiuie yeaiaioaie

i?ia?aiie?iaaiey; caeanue ia iauyniyaony, /oi oaeia YAI eee

eiiieeyoi?, ia iiyniyaony niune au?aaeaiee oeia N=N+1. Oioy

iu e iuoaeenue, aaea yoi aiciiaeii, i?iaeaiiino?e?iaaoue iieacioth

oaoieeo i?ia?aiie?iaaiey. Yoa eieaa ia i?aaeiacia/aaony auoue

ni?aai/iui ?oeiaiaenoaii ii no?oeoo?ai aeaiiuo e aeai?eoiai;

oai, aaea iu auioaeaeaiu auee naeaeaoue auai?, iu eiioeaio?e?iaa-

eenue ia ycuea.

A aeaaao ni 2-e ii 6-th ?acee/iua aniaeou “C” eceaaathony

aieaa aeaoaeueii e ianeieueei aieaa oi?iaeueii, /ai a aeaaa 1,

oioy oaea?aiea ii-i?aaeiaio aeaeaaony ia ?acai?a i?eia?ia ca-

eii/aiiuo, iieaciuo i?ia?aii, a ia ia ioaeaeueiuo o?aaiaioao.

A aeaaa 2 ianoaeaeathony iniiaiua oeiu aeaiiuo, iia?aoi?u e

au?aaeaiey. A aeaaa 3 ?anniao?eaathony oi?aaeythuea iia?aoi?u:

IF-ELSE ,WHILE ,FOR e o.ae. Aeaaa 4 ioaaouaaao ooieoeee e

no?oeoo?o i?ia?aiiu – aiaoiea ia?aiaiiua, i?aaeea ii?aaeaeai-

iuo iaeanoae aeaenoaey iienaiey e o.ae. A aeaaa 5 ianoaeaeathony

oeacaoaee e aae?aniay a?eoiaoeea. Aeaaa 6 niaea?aeeo iiae?iaiia

iienaiea no?oeoo? e iauaaeeiaiee.

A aeaaa 7 iienuaaaony noaiaea?oiay aeaeeioaea aaiaea-au-

aiaea ycuea “C”, eioi?ay iaania/eaaao noaiaea?oiue eioa?oaen n

iia?aoeeiiiie nenoaiie. Yoa aeaeeioaea aaiaea-auaiaea iiaeaea?aee-

aaaony ia anao iaoeiao, ia eioi?uo ?aaeeciaai “C”, oae /oi

i?ia?aiiu, eniieuecothuea aa aeey aaiaea, auaiaea e ae?oaeo nen-

oaiiuo ooieoeee, iiaoo ia?aiineoueny n iaeiie nenoaiu ia ae?oaoth

ii nouanoao aac eciaiaiee.

A aeaaa 8 iienuaaaony eioa?oaen iaaeaeo “C” – i?ia?aiiaie

e iia?aoeeiiiie nenoaiie “UNIX”. Oii? aeaeaaony ia aaiae-auaiae,

nenoaio oaeeia e ia?aiineiinoue. Oioy iaeioi?ua /anoe yoie

aeaau niaoeeoe/iu aeey iia?aoeeiiiie nenoaiu “UNIX”, i?ia?ai-

ienou, ia eniieuecothuea “UNIX”, ana aea aeieaeiu iaeoe caeanue ii-

eaciue iaoa?eae, a oii /enea iaeioi?ia i?aaenoaaeaiea i oii,

eae ?aaeeciaaia iaeia aa?ney noaiaea?oiie aeaeeioaee e i?aaeei-

aeaiey aeey aeinoeaeaiey ia?aiineiinoe i?ia?aiiu.

I?eeiaeaiea A niaea?aeeo ni?aai/iia ?oeiaiaenoai ii ycueo

“C”. Iii yaeyaony “ioeoeeaeueiui” eceiaeaieai neioaenena e na-

iaioeee “C” e (eneeth/ay /ae-eeai nianoaaiiue eiiieeyoi?)

ieii/aoaeueiui a?aeo?ii aeey anao aeaoniuneaiiinoae e oiouaiee

a i?aaeuaeoueo aeaaao.

· 11 –

Oae eae “C” yaeyaony ?acaeaathueiny ycueii, ?aaeeciaai-

iui ia iiiaeanoaa nenoai, /anoue iaoa?eea ianoiyuae eieae ii-

aeao ia niioaaonoaiaaoue oaeouaio ninoiyieth ?ac?aaioee ia ea-

eie-oi eiie?aoiie nenoaia. Iu noa?aeenue ecaaaaoue oaeeo i?ia-

eai e i?aaeinoa?aaaoue i aiciiaeiuo o?oaeiinoyo. A niiieoaeueiuo

neo/ayo, iaeiaei, iu iau/ii i?aaeii/eoaee iienuaaoue neooaoeeth

aeey nenoaiu “UNIX” PDP-11 , oae eae iia yaeyaony n?aaeie aeey

aieueoeinoaa i?ia?aiie?othueo ia ycuea “C”. A i?eeiaeaiee a

oaeaea iienaiu ?anoiaeaeaiey a ?aaeecaoeeyo ycuea “C” ia iniia-

iuo nenoaiao.

1. O/aaiia aaaaeaiea.

Aeaaaeoa ia/iai n auno?iai aaaaeaiey a ycue “C”. Iaoa

oeaeue – i?iaeaiiino?e?iaaoue nouanoaaiiua yeaiaiou ycuea ia ?a-

aeueiuo i?ia?aiiao, ia oaycay i?e yoii a aeaoaeyo, oi?iaeueiuo

i?aaeeao e eneeth/aieyo. A yoie aeaaa iu ia iuoaainy eceiaeeoue

ycue iieiinoueth eee oioy au no?iai (?acoiaaony, i?eaiaeeiua

i?eia?u aoaeoo ei??aeoiuie). Iu oioei eae iiaeii nei?aa aeiaan-

oe aan aei oaeiai o?iaiy, ia eioi?ii au auee au a ninoiyiee

ienaoue iieaciua i?ia?aiiu, e /oiau aeiaeoueny yoiai, iu nin?a-

aeioa/eaaainy ia iniiaiii: ia?aiaiiuo e eiinoaioao, a?eoiaoe-

ea, iia?aoi?ao ia?aaea/e oi?aaeaiey, ooieoeeyo e yeaiaioa?iuo

naaaeaieyo i aaiaea e auaiaea. Iu niaa?oaiii iaia?aiii inoaaey-

ai ca i?aaeaeaie yoie aeaau iiiaea yeaiaiou ycuea “C”, eioi-

?ua eiatho ia?ainoaiaiiia cia/aiea i?e iaienaiee aieueoeo

i?ia?aii, a oii /enea oeacaoaee, n?ooeoo?u, aieueooth /anoue ec

aiaaoiai iaai?a iia?aoi?ia ycuea “C”, ianeieueei iia?aoi?ia

ia?aaea/e oi?aaeaiey e ianiaoiia eiee/anoai aeaoaeae.

Oaeie iiaeoiae eiaao, eiia/ii, naie iaaeinoaoee. Naiui no-

uanoaaiiui yaeyaony oi, /oi iieiia iienaiea ethaiai eiie?ao-

iiai yeaiaioa ycuea ia eceaaaaony a iaeiii ianoa, a iiynia-

iey, a neeo e?aoeinoe, iiaoo i?eaanoe e iai?aaeeueiiio enoie-

eiaaieth. E?iia oiai, ec-ca iaaiciiaeiinoe eniieueciaaoue anth

iiuue ycuea, i?eia?u ieacuaathony ia noieue e?aoeeie e yeaaaio-

iuie, eae iie iiaee au auoue. E oioy iu noa?aeenue naanoe yoe

iaaeinoaoee e ieieioio, ana aea eiaeoa eo aaeaeo.

Ae?oaie iaaeinoaoie ninoieo a oii, /oi iineaaeothuea aeaau

aoaeoo iaecaaaeii iiaoi?youe iaeioi?ua /anoe yoie aeaau. Iu ia-

aeaainy, /oi oaeia iiaoi?aiea aoaeao nei?aa iiiiaaoue, /ai ?ac-

ae?aaeaoue.

Ai anyeii neo/aa, iiuoiua i?ia?aiienou aeieaeiu ieacaoueny

a ninoiyiee i?iyeno?aiiee?iaaoue iaoa?eae aeaiiie aeaau ia

naie nianoaaiiua i?ia?aiienoneea ioaeaeu. Ia/eiathuea aea aeieaeiu

a aeiiieiaiea ienaoue aiaeiae/iua iaeaiueeea naiinoiyoaeueiua

i?ia?aiiu. E oa, e ae?oaea iiaoo eniieueciaaoue yoo aeaao eae

ea?ean, ia eioi?ue aoaeoo iaaaoeaaoueny aieaa iiae?iaiua iiena-

iey, ia/eiathueany n aeaau 2.

1.1. Ha/eiaai. Aaeeinoaaiiue niinia inaieoue iiaue ycue

i?ia?aiie?iaaiey – ienaoue ia iai i?ia?aiiu. Ia?aay i?ia?ai-

ia, eioi?ay aeieaeia auoue iaienaia, – iaeia aeey anao ycueia:

iaia/aoaoue neiaa : HELLO, WORLD.

Yoi – naiue nouanoaaiiue aa?uea?; /oiau i?aiaeieaoue aai,

au aeieaeiu noiaoue caaanoe aaea-oi oaeno i?ia?aiiu, oniaoii aai

neiiieee?iaaoue, caa?oceoue, i?iaiaoue e iaeoe, aaea ieacaeanue

aaoa auaea/a. Anee au iao/eeenue ni?aaeyoueny n yoeie oaoie/an-

eeie aeaoaeyie, ana inoaeueiia n?aaieoaeueii i?inoi.

· 12 –

I?ia?aiia ia/aoe “HELLO, WORLD” ia ycuea “C” eiaao aeae:

MAIN ()

PRINTF(“HELLO, WORLDN”);

Eae i?iionoeoue yoo i?ia?aiio – caaeneo io eniieuecoaiie

aaie nenoaiu. A /anoiinoe, ia iia?aoeeiiiie nenoaia “UNIX” au

aeieaeiu caaanoe enoiaeioth i?ia?aiio a oaeea, eiy eioi?iai

ieai/eaaaony ia “.C” , iai?eia?, HELLO.C , e caoai neiiieee-

?iaaoue aa ii eiiaiaea

CC HELLO.C

Anee au ia aeiionoeee eaeie-eeai iaa?aaeiinoe , oaeie eae

i?iione neiaiea eee iai?aaeeueiia iaienaiea, eiiieeyoeey i?ie-

aeao aac niiauaiee e aoaeao nicaeai eniieiyaiue oaee n eiaiai

a.OUT . I?iaii aai ii eiiaiaea

A.OUT

i?eaaaeao e auaiaeo

HELLO, WORLD

Ia ae?oaeo nenoaiao yoe i?aaeea aoaeoo eiuie; i?ieiinoeue-oe?oeoanue n
ianoiui aaoi?eoaoii.

Oi?aaeiaiea 1-1.

I?iionoeoa yoo i?ia?aiio ia aaoae nenoaia. Iii?iaoeoa

ia aeeth/aoue ?acee/iua /anoe i?ia?aiiu e iiniio?eoa eaeea ni-

iauaiey ia ioeaeao au i?e yoii iieo/eoa.

Oaia?ue iaeioi?ua iiyniaiey e naiie i?ia?aiia. Ethaay

“C”-i?ia?aiia, eaeia au ie aue aa ?acia?, ninoieo ec iaeiie

eee aieaa “ooieoeee”, oeacuaathueo oaeoe/aneea iia?aoeee

eiiiuethoa?a, eioi?ua aeieaeiu auoue auiieiaiu. Ooieoeee a ycuea

“C” iiaeiaiu ooieoeeyi e iiaei?ia?aiiai oi?o?aia e i?ioeaaeo?ai

PL/1, ianeaey e o.ae. A iaoai i?eia?a oaeie ooieoeeae yaeyaony

MAIN. Iau/ii au iiaeaoa aeaaaoue ooieoeeyi ethaua eiaia ii aaoaio

oniio?aieth, ii MAIN – yoi iniaia eiy; auiieiaiea aaoae i?ia-

?aiiu ia/eiaaony nia/aea n ooieoeee MAIN. Yoi icia/aao, /oi

eaaeaeay i?ia?aiia aeieaeia a eaeii-oi ianoa niaea?aeaoue ooieoeeth n

eiaiai MAIN. Aeey auiieiaiey ii?aaeaeaiiuo aeaenoaee ooieoeey

MAIN iau/ii ia?auaaony e ae?oaei ooieoeeyi, /anoue ec eioi?uo

iaoiaeeony a oie aea naiie i?ia?aiia, a /anoue – a aeaeeioaeao,

niaea?aeaueo ?aiaa iaienaiiua ooieoeee.

· 13 –

Iaeiei niiniaii iaiaia aeaiiuie iaaeaeo ooieoeeyie yaeyaony

ia?aaea/a iin?aaenoaii a?aoiaioia. E?oaeua neiaee, neaaeothuea

ca eiaiai ooieoeee, caeeth/atho a naaa nienie a?aoiaioia; caeanue

iaIN – ooieoeey aac a?aoiaioia, /oi oeacuaaaony eae (). Iia-

?aoi?u, ninoaaeythuea ooieoeeth, caeeth/athony a oeao?iua neiaee

e , eioi?ua aiaeiae/iu DO-END a PL/1 eee BEGIN-END a ae-

aiea, ianeaea e o.ae. Ia?auaiea e ooieoeee inouanoaeyaony oea-

caieai aa eiaie, ca eioi?ui neaaeoao caeeth/aiiue a e?oaeua

neiaee nienie a?aoiaioia. caeanue iao ieeaeeo iia?aoi?ia CALL,

eae a oi?o?aia eee PL/1. E?oaeua neiaee aeieaeiu i?enoonoai-

aaoue e a oii neo/aa, eiaaea ooieoeey ia eiaao a?aoiaioia.

No?iea

PRINTF(“HELLO, WORLDN”);

yaeyaony ia?auaieai e ooieoeee, eioi?ia aucuaaao ooieoeeth

n eiaiai PRINTF e a?aoiaoii “HELLO, WORLDN”. Ooieoeey PRINTF

yaeyaony aeaeeioa/iie ooieoeeae, eioi?ay auaeaao auoiaeiua aeai-

iua ia oa?ieiae (anee oieueei ia oeacaii eaeia-oi ae?oaia ian-

oi iacia/aiey). A aeaiiii neo/aa ia/aoaaony no?iea neiaieia,

yaeythuayny a?aoiaioii ooieoeee.

Iineaaeiaaoaeueiinoue ec ethaiai eiee/anoaa neiaieia, cae-

eth/aiiuo a oaeaiaiiua eaau/ee “…”, iacuaaaony ‘neiaieueiie

no?ieie’ eee ‘no?i/iie eiinoaioie’. Iiea iu aoaeai eniieueci-

aaoue neiaieueiua no?iee oieueei a ea/anoaa a?aoiaioia aeey

PRINTF e ae?oaeo ooieoeee.

Iineaaeiaaoaeueiinoue N a i?eaaaeaiiie no?iea yaeyaony

iaicia/aieai ia ycuea “C” aeey ‘neiaiea iiaie no?iee’, eioi-

?ue neoaeeo oeacaieai aeey ia?aoiaea ia oa?ieiaea e eaaiio e?ath

neaaeothuae no?iee. Anee au ia aeeth/eoa N (iieaciue yenia?e-

iaio), oi iaia?oaeeoa, /oi aaoa auaea/a ia caeii/eony ia?aoi-

aeii oa?ieiaea ia iiaoth no?ieo. Eniieueciaaiea iineaaeiaaoaeue-

iinoe N – aaeeinoaaiiue niinia aaaaeaiey neiaiea iiaie no?iee

a a?aoiaio ooieoeee PRINTF; anee au iii?iaoaoa /oi-ieaoaeue

a?iaea

PRINTF(“HELLO, WORLD

“);

oi “C”-eiiieeyoi? aoaeao ia/aoaoue cei?aaeiua aeeaaiinoe/aneea

niiauaiey i iaaeinoathueo eaau/eao.

Ooieoeey PRINTF ia iaania/eaaao aaoiiaoe/aneiai ia?aoiaea

ia iiaoth no?ieo, oae /oi iiiaie?aoiia ia?auaiea e iae iiaeii

eniieueciaaoue aeey iiyoaiiie nai?ee auoiaeiie no?iee. Iaoa ia?-

aay i?ia?aiia, ia/aoathuay eaeaioe/ioth auaea/o, n oi/ii oaeei

aea oniaoii iiaea au auoue iaienaia a aeaea

MAIN()

PRINTF(“HELLO, “);

PRINTF(“WORLD”);

PRINTF(“N”);

· 14 –

Iiae/a?eiai, /oi N i?aaenoaaeyao oieueei iaeei neiaie. On-

eiaiua ‘iineaaeiaaoaeueiinoe’, iiaeiaiua N , aeatho iauee e aei-

ioneathuee ?anoe?aiea iaoaieci aeey i?aaenoaaeaiey o?oaeiuo aeey

ia/aoe eee iaaeaeeiuo neiaieia. N?aaee i?i/eo neiaieia a ycuea

“C” i?aaeoniio?aiu neaaeothuea: o – aeey oaaoeyoeee, B – aeey

aica?aoa ia iaeio iiceoeeth, ” – aeey aeaieiie eaau/ee e aeey

naiie ia?aoiie einie /a?ou.

Oi?aaeiaiea 1-2.

I?iaaaeeoa yenia?eiaiou aeey oiai, /oiau ociaoue /oi i?ie-

cieaeao, anee a no?iea, yaeythuaeny a?aoiaioii ooieoeee PRINTF

aoaeao niaea?aeaoueny X, aaea X – iaeioi?ue neiaie, ia aoiaeyuee

a auoai?eaaaeaiiue nienie.

1.2. Ia?aiaiiua e a?eoiaoeea.

Neaaeothuay i?ia?aiia ia/aoaao i?eaaaeaiioth ieaea oaaeeoeo

oaiia?aoo? ii Oa?aiaaeoo e eo yeaeaaeaioia ii noia?aaeoniie

oeaea Oeaeueney, eniieuecoy aeey ia?aaiaea oi?ioeo

C = (5/9)*(F-32).

0 -17.8

20 -6.7

40 4.4

60 15.6

… …

260 126.7

280 137.8

300 140.9

Oaia?ue naia i?ia?aiia:

/* PRINT FAHRENHEIT-CELSIUS TABLE

FOR F = 0, 20, …, 300 */

MAIN()

INT LOWER, UPPER, STEP;

FLOAT FAHR, CELSIUS;

LOWER = 0; /* LOWER LIMIT OF TEMPERATURE

TABLE */

UPPER =300; /* UPPER LIMIT */

STEP = 20; /* STEP SIZE */

FAHR = LOWER;

WHILE (FAHR = ‘0’ && C = ‘0’ && C = ‘0’ && C 0 */

INT X,N;

INT I, P;

P = 1;

FOR (I =1; I 0;

VERSION 2 */

INT X,N;

INT P;

FOR (P = 1; N > 0; –N)

P = P * X;

RETURN (P);

A?aoiaio N eniieuecoaony eae a?aiaiiay ia?aiaiiay; ec ia-

ai au/eoaaony aaeeieoea aei oao ii?, iiea ii ia noaiao ioeai.

Ia?aiaiiay I caeanue aieueoa ia ioaeia. /oiau ie i?ienoiaeeei n N

aioo?e POWER yoi ieeae ia aeeyao ia a?aoiaio, n eioi?ui ia?-

aiia/aeueii ia?aoeeenue e ooieoeee POWER.

I?e iaiaoiaeeiinoe ana aea iiaeii aeiaeoueny, /oiau ooieoeey

eciaieea ia?aiaiioth ec aucuaathuae i?ia?aiiu. Yoa i?ia?aiia

aeieaeia iaania/eoue onoaiiaeaiea aae?ana ia?aiaiiie /oaoie/an-

ee, /a?ac oeacaoaeue ia ia?aiaiioth/, a a aucuaaaiie ooieoeee

iaaei iienaoue niioaaonoaothuee a?aoiaio eae oeacaoaeue e nnu-

eaoueny e oaeoe/aneie ia?aiaiiie einaaiii /a?ac iaai. Iu ?an-

niio?ei yoi iiae?iaii a aeaaa 5.

Eiaaea a ea/anoaa a?aoiaioa aunooiaao eiy ianneaa, oi

oaeoe/aneei cia/aieai, ia?aaeaaaaiui ooieoeee, yaeyaony aae?an

ia/aea ianneaa. /Caeanue iao ieeaeiai eiie?iaaiey yeaiaioia

ianneaa/. N iiiiuueth eiaeaenaoeee e aae?ana ia/aea ooieoeey iiaeao

iaeoe e eciaieoue ethaie yeaiaio ianneaa. Yoi – oaia neaaeothua-

ai ?acaeaea.

· 32 –

1.9. Ianneau neiaieia.

Ii-aeaeeiiio naiui iauei oeiii ianneaa a “C” yaeyaony

iannea neiaieia. *oiau i?ieeethno?e?iaaoue eniieueciaaiea ian-

neaia neiaieia e ia?aaaouaathueo eo ooieoeee, aeaaaeoa iaieoai

i?ia?aiio, eioi?ay /eoaao iaai? no?ie e ia/aoaao naioth aeeei-

ioth ec ieo. Iniiaiay noaia i?ia?aiiu aeinoaoi/ii i?inoa:

WHILE (eiaaony aua no?iea)

IF (yoa no?iea aeeeiiaa naiie aeeeiiie ec

i?aaeuaeoueo)

caiiiieoue yoo no?ieo e aa aeeeio

iaia/aoaoue naioth aeeeiioth no?ieo

Ii yoie noaia ynii, /oi i?ia?aiia anoanoaaiiui ia?acii

?aniaaeaaony ia ianeieueei /anoae. Iaeia /anoue /eoaao iiaoth

no?ieo, ae?oaay i?iaa?yao aa, o?aouey caiiieiaao, a inoaeueiua

/anoe i?ia?aiiu oi?aaeytho yoei i?ioeannii.

Iineieueeo ana oae i?ae?anii aeaeeony, auei au oi?ioi e

iaienaoue i?ia?aiio niioaaonaothuei ia?acii. Aeaaaeoa nia/aea

iaieoai ioaeaeueioth ooieoeeth GETLINE, eioi?ay aoaeao ecaeaeaoue

neaaeothuoth no?ieo ec oaeea aaiaea; yoi – iaiauaiea ooieoeee

GETCHAR. iu iiiuoaainy naeaeaoue yoo ooieoeeth ii aiciiaeiinoe

aieaa aeaeie, /oiau iia auea iieaciie e a ae?oaeo neooaoeeyo.

Eae ieieioi GETLINE aeieaeia ia?aaeaaaoue neaiae i aiciiaeiii ii-

yaeaiee eiioea oaeea; aieaa iauee iieaciue aa?eaio iia au ia-

?aaeaaaoue aeeeio no?iee eee ioeue, anee ano?aoeony eiiaoe oaeea.

ioeue ia iiaeao auoue aeeeiie no?iee, oae eae eaaeaeay no?iea ni-

aea?aeeo ii e?aeiae ia?a iaeei neiaie; aeaaea no?iea, niaea?aeauay

oieueei neiaie iiaie no?iee, eiaao aeeeio 1.

Eiaaea iu iaoiaeei no?ieo, eioi?ay aeeeiiaa naiie aeeeiiie

ec i?aaeuaeoueo, oi aa iaaei aaea-oi caiiiieoue. Yoi iaaiaeeo ia

iuneue i ae?oaie ooieoeee, COPY , eioi?ay aoaeao eiie?iaaoue ii-

aoth no?ieo a ianoi o?aiaiey.

Iaeiiaoe, iai ioaeia iniiaiay i?ia?aiia aeey oi?aaeaiey

ooieoeeyie GETLINE e COPY . Aio ?acoeueoao :

#DEFINE MAXLINE 1000 /* MAXIMUM INPUT

LINE SIZE */

MAIN() /* FIND LONGEST LINE */

INT LEN; /* CURRENT LINE LENGTH */

INT MAX; /* MAXIMUM LENGTH SEEN SO FAR */

CHAR LINE[MAXLINE]; /* CURRENT INPUT LINE */

CHAR SAVE[MAXLINE]; /* LONGEST LINE, SAVED */

MAX = 0;

WHILE ((LEN = GETLINE(LINE, MAXLINE)) > 0)

IF (LEN > MAX)

MAX = LEN;

COPY(LINE, SAVE);

IF (MAX > 0) /* THERE WAS A LINE */

PRINTF(“%S”, SAVE);

· 33 –

GETLINE(S,LIM) /* GET LINE INTO S,RETURN LENGTH */

CHAR S[];

INT LIM;

INT C, I;

FOR(I=0;I 0 )

IF ( LEN > MAX )

MAX = LEN;

COPY();

IF ( MAX > 0 ) /* THERE WAS A LINE */

PRINTF( “%S”, SAVE );

GETLINE() /* SPECIALIZED VERSION */

INT C, I;

EXTERN CHAR LINE[];

FOR (I = 0; I > ==’0′ && S[I]= ‘A’ && C J, e

eiae/aneea au?aaeaiey, naycaiiua iia?aoeeyie && e !!, ii ii-

?aaeaeaieth eiatho cia/aiea 1, anee iie enoeiiu, e 0, anee iie

eiaeiu. Oaeei ia?acii, i?enaaeaaiea

ISDIGIT = C >= ‘0’ && C > naeaea ai?aai

^ aeiiieiaiea (oia?iay iia?aoeey)

“” eiieoe?oao aa?oeeaeueioth /a?oo.

Iiaeoiaay iia?aoeey AND /anoi eniieuecoaony aeey ianee?iaaiey

iaeioi?iai iiiaeanoaa aeoia; iai?eia?, iia?aoi?

C = N & 0177

· 52 –

ia?aaeaao a ‘n’ naiue ieaaeoeo aeoia N , iieaaay inoaeueiua ?aa-

iuie ioeth. Iia?aoeey ‘y’ iiaeoiaiai OR eniieuecoaony aeey aeeth-

/aiey aeoia:

C = X y MASK

onoaiaaeeaaao ia aaeeieoeo oa aeou a o , eioi?ua ?aaiu aaeeieoea

a MASK.

Neaaeoao auoue aieiaoaeueiui e ioee/aoue iiaeoiaua iia?aoeee

& e ‘y’ io eiae/aneeo naycie && e !! , Eioi?ua iiae?acoia-

aatho au/eneaiea cia/aiey enoeiiinoe neaaa iai?aai. Iai?eia?,

anee o=1, a Y=2, oi cia/aiea o&Y ?aaii ioeth , a oi a?aiy eae

cia/aiea X&&Y ?aaii aaeeieoea./ii/aio?/

Iia?aoeee naeaeaa > inouanoaeytho niioaaonoaaiii

naeaea aeaai e ai?aai naiaai eaaiai iia?aiaea ia /enei aeoiauo

iiceoeee, caaeaaaaiuo i?aaui iia?aiaeii. Oaeei ia?acii , o> (P+1-N)) & ^(^0 > (P+1-N) naeaeaaao aeaeaaiia iiea a i?aaue eiiaoe

neiaa. Iienaiea a?aoiaioa X eae UNSIGNED aa?aioe?oao, /oi

i?e naeaeaa ai?aai inaiaiaeaeathueany aeou aoaeoo caiieiyoueny io-

eyie, a ia niaea?aeeiui ciaeiaiai aeoa, iacaaeneii io oiai, ia

eaeie iaoeia i?iioneaaony i?ia?aiia. Ana aeou eiinoaioiiai

au?aaeaiey ^0 ?aaiu 1; naeaea aai ia N iiceoeee aeaai n ii-

iiuueth iia?aoeee ^0> & ^ !

Anee a1 e a2 – au?aaeaiey, oi

· 54 –

a1 ii= a2

yeaeaaeaioii

a1 = (a1) ii (a2)

ca eneeth/aieai oiai, /oi au?aaeaiea a1 au/eneyaony oieueei

iaeei ?ac. Ia?aoeoa aieiaiea ia e?oaeua neiaee aie?oa a2:

X *= Y + 1

oi

X = X * (Y + 1)

ia

X = X * Y + 1

A ea/anoaa i?eia?a i?eaaaeai ooieoeeth BITCOUNT, eioi?ay iiaen/eouaaao
/enei ?aaiuo 1 aeoia o oeaeiai a?aoiaioa.

BITCOUNT(N) /* COUNT 1 BITS IN N */

UNSIGNED N;

(

INT B;

FOR (B = 0; N != 0; N >>= 1)

IF (N & 01)

B++;

RETURN(B);

)

Ia aiai?y oaea i e?aoeinoe, oaeea iia?aoi?u i?eaaeaaiey

eiatho oi i?aeiouanoai, /oi iie eo/oa niioaaonoaotho ia?aco

/aeiaa/aneiai iuoeaiey. Iu aiai?ei: “i?eaaaeoue 2 e I” eee

“oaaee/eoue I ia 2”, ii ia “acyoue I, i?eaaaeoue 2 e iiianoeoue

?acoeueoao iiyoue a I”. Eoae, I += 2. E?iia oiai, a a?iiicaeeeo

au?aaeaieyo, iiaeiaiuo

YYVAL[YYPV[P3+P4] + YYPV[P1+P2]] += 2

Taeay iia?aoeey i?enaaeaaiey iaeaa/aao iiieiaiea i?ia?aiiu,

oae eae /eoaoaeue ia aeieaeai ne?oioeacii i?iaa?youe, yaeythony

ee aeaa aeeeiiuo au?aaeaiey aeaenoaeoaeueii iaeeiaeiauie, eee ca-

aeoiuaaoueny, ii/aio iie ia niaiaaeatho. Oaeay iia?aoeey i?enaae-

aaiey iiaeao aeaaea iiii/ue eiiieeyoi?o iieo/eoue aieaa yooaeoea-

ioth i?ia?aiio.

Iu oaea eniieueciaaee oio oaeo, /oi iia?aoeey i?enaaeaaiey

eiaao iaeioi?ia cia/aiea e iiaeao aoiaeeoue a au?aaeaiey; naiue

oeie/iue i?eia?

· 55 –

WHILE ((C = GETCHAR()) != EOF)

i?enaaeaaiey, eniieuecothuea ae?oaea iia?aoeee i?enaaeaaiey (+=,

-= e o.ae.) oaeaea iiaoo aoiaeeoue a au?aaeaiey, oioy yoi neo/a-

aony ?aaea.

Oeiii au?aaeaiey i?enaaeaaiey yaeyaony oei aai eaaiai

iia?aiaea.

Oi?aaeiaiea 2-9.

A aeaie/iie nenoaia n/eneaiey iia?aoeey X&(X-1) iaioeyao

naiue i?aaue ?aaiue 1 aeo ia?aiaiiie X.(ii/aio?) eniieuecoeoa

yoi caia/aiea aeey iaienaiey aieaa auno?ie aa?nee ooieoeee

BITCOUNT.

2.11. Oneiaiua au?aaeaiey.

Iia?aoi?u

IF (A > B)

Z = A;

ELSE

Z = B;

eiia/ii au/eneytho a Z iaeneioi ec a e a. Oneiaiia au?aaeaiea,

caienaiiia n iiiiuueth oa?ia?iie iia?aoeee “?:”, i?aaeinoaaeyao

ae?oaoth aiciiaeiinoue aeey caiene yoie e aiaeiae/iuo eiino?oe-

oeee. A au?aaeaiee

a1 ? A2 : a3

nia/aea au/eneyaony au?aaeaiea a1. Anee iii ioee/ii io ioey

(enoeiii), oi au/eneyaony au?aaeaiea a2, eioi?ia e noaiiaeony

cia/aieai oneiaiiai au?aaeaiey. A i?ioeaiii neo/aa au/eneyao-

ny a3, e iii noaiiaeony cia/aieai oneiaiiai au?aaeaiey. Eaae-

aeue ?ac au/eneyaony oieueei iaeii ec au?aaeaiey a2 e a3. Oaeei

ia?acii, /oiau iieiaeeoue Z ?aaiui iaeneioio ec a e a, iiaeii

iaienaoue

Z = (A > B) ? A : B; /* Z = MAX(A,B) */

Neaaeoao iiae/a?eiooue, /oi oneiaiia au?aaeaiea aeaenoaeoaeue-

ii yaeyaony au?aaeaieai e iiaeao eniieueciaaoueny oi/ii oae aea,

eae ethaia ae?oaia au?aaeaiea. Anee a2 e a3 eiatho ?aciua oeiu,

oi oei ?acoeueoaoa ii?aaeaeyaony ii i?aaeeai i?aia?aciaaiey,

?anniio?aiiui ?aiaa a yoie aeaaa. iai?eia?, anee F eiaao oei

FLOAT, a N – oei INT, oi au?aaeaiea

(N > 0) ? F : N

Eiaao oei DOUBLE iacaaeneii io oiai, iieiaeeoaeueii ee N eee

iao.

· 56 –

Oae eae o?iaaiue noa?oeinoaa iia?aoeee ?: i/aiue iecie,

i?yii iaae i?enaaeaaieai, oi ia?aia au?aaeaiea a oneiaiii au-

?aaeaiee iiaeii ia caeeth/aoue a e?oaeua neiaee. Iaeiaei, iu ana

aea ?aeiiaiaeoai yoi aeaeaoue, oae eae neiaee aeaeatho oneiaioth

/anoue au?aaeaiey aieaa caiaoiie.

Eniieueciaaiea oneiaiuo au?aaeaiee /anoi i?eaiaeeo e ei?io-

eei i?ia?aiiai. Iai?eia?, neaaeothuee ieaea iia?aoi? oeeeea ia-

/aoaao N yeaiaioia ianneaa, ii 10 a no?iea, ?acaeaeyy eaaeaeue

noieaaoe iaeiei i?iaaeii e caeai/eaay eaaeaeoth no?ieo (aeeth/ay

iineaaeithth) iaeiei neiaieii ia?aaiaea no?iee.

OR (I = 0; I . LEFT TO RIGHT

! ^ ++ — – (TYPE) * & SIZEOF RIGHT TO LEFT

* / % LEFT TO RIGHT

+ – LEFT TO RIGHT

> LEFT TO RIGHT

>= LEFT TO RIGHT

· 57 –

== != LEFT TO RIGHT

& LEFT TO RIGHT

^ LEFT TO RIGHT

! LEFT TO RIGHT

&& LEFT TO RIGHT

!! LEFT TO RIGHT

?: RIGHT TO LEFT

= += -= ETC. RIGHT TO LEFT

, (CHAPTER 3) LEFT TO RIGHT

Iia?aoeee -> e . Eniieuecothony aeey aeinooia e yeaiaioai no?oe-

oo?; iie aoaeoo iienaiu a aeaaa 6 aianoa n SIZEOF (?acia?

iauaeoa). A aeaaa 5 ianoaeaeathony iia?aoeee * (einaaiiay aae?a-

naoeey) e & (aae?an).

Ioiaoei, /oi o?iaaiue noa?oeinoaa iiaeoiauo eiae/aneeo iia?a-

oeee &, ^ e y ieaea o?iaiy iia?aoeee == e !=. Yoi i?eaiaeeo e

oiio, /oi inouanoaeythuea iiaeoiaoth i?iaa?eo au?aaeaiey, ii-

aeiaiua

IF ((X & MASK) == 0) …

Aeey iieo/aiey i?aaeeueiuo ?acoeueoaoia aeieaeiu caeeth/aoueny a

e?oaeua neiaee.

Eae oaea ioia/aeinue ?aiaa, au?aaeaiey, a eioi?ua aoiaeeo

iaeia ec annioeeaoeaiuo e eiiiooaoeaiuo iia?aoeee (*, +, &, ^,

y), iiaoo ia?aa?oiie?iauaaoueny, aeaaea anee iie caeeth/aiu a

e?oaeua neiaee. A aieueoeinoaa neo/aaa yoi ia i?eaiaeeo e ea-

eei au oi ie auei ?anoiaeaeaieyi; a neooaoeeyo, aaea oaeea ?an-

oiaeaeaiey ana aea aiciiaeiu, aeey iaania/aiey ioaeiiai ii?yaeea

au/eneaiee iiaeii eniieueciaaoue yaiua i?iiaaeooi/iua ia?aiai-

iua.

A ycuea “C”, eae e a aieueoeinoaa ycueia, ia oeene?oaony

ii?yaeie au/eneaiey iia?aiaeia a iia?aoi?a. Iai?eia? a iia?a-

oi?a aeaea

X = F() + G();

nia/aea iiaeao auoue au/eneaii F, a iioii G, e iaiai?io; iiy-

oiio, anee eeai F, eeai G eciaiytho aiaoithth ia?aiaiioth, io

eioi?ie caaeneo ae?oaie iia?aiae, oi cia/aiea X iiaeao caaenaoue

io ii?yaeea au/eneaiee. Aeey iaania/aiey ioaeiie iineaaeiaaoaeue-

iinoe i?iiaaeooi/iua ?acoeueoaou iiaeii iiyoue caiiieiaoue ai

a?aiaiiuo ia?aiaiiuo.

Iiaeiaiui aea ia?acii ia oeene?oaony ii?yaeie au/eneaiey

a?aoiaioia ooieoeee, oae /oi iia?aoi?

PRINTF(“%D %DN”,++N,POWER(2,N));

· 58 –

iiaeao aeaaaoue (e aeaenoaeoaeueii aeaao) ia ?aciuo iaoeiao ?aciua

?acoeueoaou a caaeneiinoe io oiai, oaaee/eaaaony ee N aei eee

iinea ia?auaiey e ooieoeee POWER. I?aaeeueiui ?aoaieai, eiia/-

ii, yaeyaony caienue

++N;

PRINTF(“%D %DN”,N,POWER(2,N));

Ia?auaiey e ooieoeeyi, aeiaeaiiua iia?aoeee i?enaaeaaiey,

iia?aoeee oaaee/aiey e oiaiueoaiey i?eaiaeyo e oae iacuaaaiui

“iiai/iui yooaeoai” – iaeioi?ua ia?aiaiiua eciaiythony eae

iiai/iue ?acoeueoao au/eneaiey au?aaeaiee. A ethaii au?aaeaiee,

a eioi?ii aicieeatho iiai/iua yooaeou, iiaoo nouanoaiaaoue

i/aiue oiieea caaeneiinoe io ii?yaeea, a eioi?ii ii?aaeaeythony

aoiaeyuea a iaai ia?aiaiiua. i?eia?ii oeie/iie iaoaea/iie ne-

ooaoeee yaeyaony iia?aoi?

A[I] = I++;

Aicieeaao aii?in, noa?ia eee iiaia cia/aiea I neoaeeo a ea-

/anoaa eiaeaena. Eiiieeyoi? iiaeao iinooiaoue ?aciuie niiniaaie

e a caaeneiinoe io naiae eioa?i?aoaoeee auaeaaaoue ?aciua ?a-

coeueoaou. Oio neo/ae, eiaaea i?ienoiaeyo iiai/iua yooaeou

(i?enaaeaaiea oaeoe/aneei ia?aiaiiui), – inoaaeyaony ia on-

iio?aiea eiiieeyoi?a, oae eae iaeeo/oee ii?yaeie neeueii caae-

neo io a?oeoaeoo?u iaoeiu.

Ec yoeo ?annoaeaeaiee auoaeaao oaeay ii?aeue: iaienaiea

i?ia?aii, caaenyueo io ii?yaeea au/eneaiee, yaeyaony ieioei

iaoiaeii i?ia?aiie?iaaiey ia ethaii ycuea. Eiia/ii, iaiaoiaeeii

ciaoue, /aai neaaeoao ecaaaaoue, ii anee au ia a eo?na, eae ia-

eioi?ua aaue ?aaeeciaaiu ia ?aciuo iaoeiao, yoi iaaaaeaiea

iiaeao i?aaeio?aieoue aan io iai?eyoiinoae. (Ioeaaei/iay i?ia-

?aiia LINT oeaaeao aieueoeinoai iano, caaenyueo io ii?yaeea au-

/eneaiee.

· 59 –

3. Iioie oi?aaeaiey

Oi?aaeythuea iia?aoi?u ycuea ii?aaeaeytho ii?yaeie au/enea-

iee. A i?eaaaeaiiuo ?aiaa i?eia?ao iu oaea ano?a/aeenue n iae-

aieaa oiio?aaeoaeueiuie oi?aaeythueie eiino?oeoeeyie ycuea “C”;

caeanue iu iieoai inoaeueiua iia?aoi?u oi?aaeaiey e ooi/iei

aeaenoaey iia?aoi?ia, ianoaeaeaaoeony ?aiaa.

3.1. Iia?aoi?u e aeiee

Oaeea au?aaeaiey, eae X=0, eee I++, eee PRINTF(…),

noaiiayony iia?aoi?aie, anee ca ieie neaaeoao oi/ea n caiy-

oie, eae, iai?eia?,

X = 0;

I++;

PRINTF(…);

A ycuea “C” oi/ea n caiyoie yaeyaony i?eciaeii eiioea iia?a-

oi?a, a ia ?acaeaeeoaeai iia?aoi?ia, eae a ycueao oeia aeai-

ea.

Oeao?iua neiaee /( e /) eniieuecothony aeey iauaaeeiaiey

iienaiee e iia?aoi?ia a ninoaaiie iia?aoi? eee aeie, oae /oi

iie ieacuaathony neioaene/anee yeaeaaeaioiu iaeiiio iia?aoi?o.

Iaeei yaiue i?eia? oaeiai oeia aeatho oeao?iua neiaee, a eioi-

?ua caeeth/athony iia?aoi?u, ninoaaeythuea ooieoeeth, ae?oaie –

oeao?iua neiaee aie?oa a?oiiu iia?aoi?ia a eiino?oeoeeyo IF,

ELSE, WHILE e FOR.(ia naiii aeaea ia?aiaiiua iiaoo auoue iie-

naiu aioo?e ethaiai aeiea; iu iiaiai?ei ia yoii a aeaaa 4).

Oi/ea n caiyoie ieeiaaea ia noaaeony iinea ia?aie oeao?iie

neiaee, eioi?ay caaa?oaao aeie.

3.2. IF – ELSE

Iia?aoi? IF – ELSE eniieuecoaony i?e iaiaoiaeeiinoe naea-

eaoue auai?. Oi?iaeueii neioaenen eiaao aeae

IF (au?aaeaiea)

iia?aoi?-1

ELSE

iia?aoi?-2,

Aaea /anoue ELSE yaeyaony iaiaycaoaeueiie. Nia/aea au/eney-

aony au?aaeaiea; anee iii “enoeiii” /o.a. cia/aiea au?aaeaiey

ioee/ii io ioey/, oi auiieiyaony iia?aoi?-1. Anee iii eiaeii

/cia/aiea au?aaeaiey ?aaii ioeth/, e anee anoue /anoue n ELSE,

oi aianoi iia?aoi?a-1 auiieiyaony iia?aoi?-2.

· 60 –

Oae eae IF i?inoi i?iaa?yao /eneaiiia cia/aiea au?aaea-

iey, oi aiciiaeii iaeioi?ia nie?auaiea caiene. Naiie i/aaeae-

iie aiciiaeiinoueth yaeyaony caienue

IF (au?aaeaiea)

aianoi

IF (au?aaeaiea !=0)

eiiaaea oaeay caienue yaeyaony yniie e anoanoaaiiie, ii a?aia-

iaie iia noaiiaeony caaaaei/iie.

Oi, /oi /anoue ELSE a eiino?oeoeee IF – ELSE yaeyaony iai-

aycaoaeueiie, i?eaiaeeo e aeaoniuneaiiinoe a neo/aa, eiaaea ELSE

iioneaaony ai aeiaeaiiie iineaaeiaaoaeueiinoe iia?aoi?ia IF.

Yoa iaiaeiicia/iinoue ?ac?aoaaony iau/iui ia?acii – ELSE nay-

cuaaaony n aeeaeaeoei i?aaeuaeouei IF, ia niaea?aeauei ELSE.

Iai?eia?, a

IF ( N > 0 )

IF( A > B )

Z = A;

ELSE

Z = B;

eiino?oeoeey ELSE ioiineony e aioo?aiiaio IF, eae iu e iiea-

caee, naeaeioa ELSE iiae niioaaonoaothuee IF. Anee yoi ia oi,

/oi au oioeoa, oi aeey iieo/aiey ioaeiiai niioaaonoaey iaiaoi-

aeeii eniieueciaaoue oeao?iua neiaee:

IF (N > 0)

IF (A > B)

Z = A;

ELSE

Z = B;

Taeay aeaoniuneaiiinoue iniaaiii iaaoaia a neooaoeeyo oeia

IF (N > 0)

FOR (I = 0; I 0)

PRINTF(“…”);

RETURN(I);

ELSE /* WRONG */

PRINTF(“ERROR – N IS ZERON”);

· 61 –

Caienue ELSE iiae IF ynii iieacuaaao, /aai au oioeoa, ii eii-

ieeyoi? ia iieo/eo niioaaonoaothuaai oeacaiey e nayaeao ELSE n

aioo?aiiei IF. Ioeaee oaeiai ?iaea i/aiue o?oaeii iaia?oaeeaatho-

ny.

Iaaeaeo i?i/ei, ia?aoeoa aieiaiea, /oi a

IF (A > B)

Z = A;

ELSE

Z = B;

iinea Z=A noieo oi/ea n caiyoie. Aeaei a oii, /oi niaeanii

a?aiiaoe/aneei i?aaeeai ca IF aeieaeai neaaeiaaoue iia?aoi?, a

au?aaeaiea oeia Z=A, yaeythuaany iia?aoi?ii, anaaaea caeai/eaa-

aony oi/eie n caiyoie.

3.3. ELSE – IF

Eiino?oeoeey

IF (au?aaeaiea)

iia?aoi?

ELSE IF (au?aaeaiea)

iia?aoi?

ELSE IF (au?aaeaiea)

iia?aoi?

ELSE

iia?aoi?

ano?a/aaony ianoieueei /anoi, /oi caneoaeeaaao ioaeaeueiiai

e?aoeiai ?anniio?aiey. Oaeay iineaaeiaaoaeueiinoue iia?aoi?ia

IF yaeyaony iaeaieaa ?ani?ino?aiaiiui niiniaii i?ia?aiie?i-

aaiey auai?a ec ianeieueeeo aiciiaeiuo aa?eaioia. au?aaeaiey

i?iniao?eaathony iineaaeiaaoaeueii; anee eaeia-oi au?aaeaiea

ieacuaaaony enoeiiui,oi auiieiyaony ioiinyueeny e iaio iia-

?aoi?, e yoei any oeaii/ea caeai/eaaaony. Eaaeaeue iia?aoi? ii-

aeao auoue eeai ioaeaeueiui iia?aoi?ii, eeai a?oiiie iia?aoi?ia

a oeao?iuo neiaeao.

Iineaaeiyy /anoue n ELSE eiaao aeaei ni neo/aai, eiaaea ie

iaeii ec i?iaa?yaiuo oneiaee ia auiieiyaony. Eiiaaea i?e yoii

ia iaaei i?aaei?eieiaoue ieeaeeo yaiuo aeaenoaee; a yoii neo/aa

oaino

ELSE

iia?aoi?

iiaeao auoue iiouai, eee aai iiaeii eniieueciaaoue aeey eiio?iey,

/oiau cana/ue “iaaiciiaeiia” oneiaea.

· 62 –

Aeey eeethno?aoeee auai?a ec o?ao aiciiaeiuo aa?eaioia i?e-

aaaeai i?ia?aiio ooieoeee, eioi?ay iaoiaeii iieiaeiiiai aeaeaiey

ii?aaeaeyao, iaoiaeeony ee aeaiiia cia/aiea o a ioni?oe?iaaiiii

ianneaa V. Yeaiaiou ianneaa V aeieaeiu auoue ?aniieiaeaiu a ii-

?yaeea aic?anoaiey. Ooieoeey aica?auaao iiia? iiceoeee (/enei

iaaeaeo 0 e N-1), a eioi?ie cia/aiea o iaoiaeeony a V, e -1,

anee o ia niaea?aeeony a V.

BINARY(X, V, N) /* FIND X IN V[0]…V[N-1] */

INT X, V[], N;

INT LOW, HIGH, MID;

LOW = 0;

HIGH = N – 1;

WHILE (LOW V[MID])

LOW = MID + 1;

ELSE /* FOUND MATCH */

RETURN(MID);

RETURN(-1);

Iniiaiie /anoueth eaaeaeiai oaaa aeai?eoia yaeyaony i?iaa?-

ea, aoaeao ee o iaiueoa, aieueoa eee ?aaai n?aaeiaio yeaiaioo

V[MID]; eniieueciaaiea eiino?oeoeee ELSE – IF caeanue aiieia an-

oanoaaiii.

3.4. Ia?aeeth/aoaeue

Iia?aoi? SWITCH aeaao niaoeeaeueiue niinia auai?a iaeiiai ec

iiiaeo aa?eaioia, eioi?ue caeeth/aaony a i?iaa?ea niaiaaeaiey

cia/aiey aeaiiiai au?aaeaiey n iaeiie ec caaeaiiuo eiinoaio e

niioaaonoaothuai aaoaeaiee. A aeaaa 1 iu i?eaaee i?ia?aiio

iiaen/aoa /enea aoiaeaeaiee eaaeaeie oeeo?u, neiaieia ionouo i?i-

iaaeooeia e anao inoaeueiuo neiaieia, eniieuecothuoth iineaaeiaa-

oaeueiinoue IF…ELSE IF…ELSE. Aio oa aea naiay i?ia?aiia n

ia?aeeth/aoaeai.

· 63 –

MAIN() /* COUNT DIGITS,WHITE SPACE, OTHERS */

INT C, I, NWHITE, NOTHER, NDIGIT[10];

NWHITE = NOTHER = 0;

FOR (I = 0; I = ‘0’ && S[I] 0; GAP /= 2)

FOR (I = GAP; I =0 && V[J]>V[J+GAP]; J-=GAP)

TEMP = V[J];

V[J] = V[J+GAP];

V[J+GAP] = TEMP;

Caeanue eiathony o?e aeiaeaiiuo oeeeea. Naiue aiaoiee oeeee oi?aa-

eyao eioa?aaeii iaaeaeo n?aaieaaaiuie yeaiaioaie, oiaiueoay aai

io N/2 aaeaia i?e eaaeaeii i?ioiaea, iiea ii ia noaiao ?aaiui

ioeth. N?aaeiee oeeee n?aaieaaao eaaeaeoth ia?o yeaiaioia, ?acaea-

eaiiuo ia aaee/eio eioa?aaea; naiue aioo?aiiee oeeee ia?an-

oaaeyao ethaoth iaoii?yaei/aiioth ia?o. Oae eae eioa?aae a eiioea

eiioeia naiaeeony e aaeeieoea, ana yeaiaiou a ?acoeueoaoa oii?y-

aei/eaathony i?aaeeueii. Ioiaoei, /oi a neeo iauiinoe eiino?oe-

oeee FOR aiaoiee oeeee oeeaaeuaaaony a oo aea naioth oi?io, /oi e

inoaeueiua, oioy ii e ia yaeyaony a?eoiaoe/aneie i?ia?anneae.

Iineaaeiae iia?aoeeae ycuea “C” yaeyaony caiyoay “,”, ei-

oi?ay /aua anaai eniieuecoaony a iia?aoi?a FOR. Aeaa au?aaea-

iey, ?acaeaeaiiua caiyoie, au/eneythony neaaa iai?aai, i?e/ai

oeiii e cia/aieai ?acoeueoaoa yaeythony oei e cia/aiea i?aaiai

iia?aiaea. Oaeei ia?acii, a ?acee/iua /anoe iia?aoi?a FOR

iiaeii aeeth/eoue ianeieueei au?aaeaiee, iai?eia?, aeey ia?aeeaeue-

iiai eciaiaiey aeaoo eiaeaenia. Yoi eeethno?e?oaony ooieoeeae

REVERSE(S), eioi?ay ?aniieaaaao no?ieo S a ia?aoiii ii?yaeea

ia oii aea ianoa.

REVERSE(S) /* REVERSE STRING S IN PLACE */

CHAR S[];

INT C, I, J;

FOR(I = 0, J = STRLEN(S) – 1; I 0); /* DELETE IT */

IF (SIGN 0)

WHILE (–N >= 0)

IF (LINE[N] != ‘ ‘ && LINE[N] != ‘T’

&& LINE[N] != ‘N’)

BREAK;

LINE[N+1] = ‘0’;

PRINTF(“%SN”,LINE);

Ooieoeey GETLINE aica?auaao aeeeio no?iee. Aioo?aiiee oeeee

ia/eiaaony n iineaaeiaai neiaiea LINE (iaiiiiei, /oi—N

oiaiueoaao N aei eniieueciaaiey aai cia/aiey) e aeaeaeaony a ia-

?aoiii iai?aaeaiee a iienea ia?aiai neiaiea , eioi?ue ioee-

/ai io i?iaaea, oaaoeyoeee eee iiaie no?iee. Oeeee i?a?uaaao-

ny, eiaaea eeai iaeaeai oaeie neiaie, eeai N noaiiaeony io?e-

oeaoaeueiui (o.a., eiaaea i?iniio?aia any no?iea). Niaaooai aai

oaaaeeoueny, /oi oaeia iiaaaeaiea i?aaeeueii e a oii neo/aa,

eiaaea no?iea ninoieo oieueei ec neiaieia ionouo i?iiaaeooeia.

A ea/anoaa aeueoa?iaoeau e BRaae iiaeii aaanoe i?iaa?eo a

nai oeeee:

WHILE ((N = GETLINE(LINE,MAXLINE)) > 0)

WHILE (–N >= 0

&& (LINE[N] == ‘ ‘ !! LINE[N] == ‘T’

!! LINE[N] == ‘N’))

;

· 71 –

Yoi onooiaao i?aaeuaeouaio aa?eaioo, oae eae i?iaa?ea noaii-

aeony o?oaeiaa aeey iiieiaiey. I?iaa?ie, eioi?ua o?aaotho ia-

?aieaoaiey &&, !!, ! E e?oaeuo neiaie, ii aiciiaeiinoe nea-

aeoao ecaaaaoue.

3.8. Iia?aoi? CONTINUE

Iia?aoi? CONTINUE ?iaenoaaiai iia?aoi?o BRaae, ii eniieue-

coaony ?aaea; ii i?eaiaeeo e ia/aeo neaaeothuae eoa?aoeee ioaaou-

aathuaai oeeeea (FOR, WHILE, DO ). A oeeeeao WHILE e DO yoi ic-

ia/aao iaiin?aaenoaaiiue ia?aoiae e auiieiaieth i?iaa?i/iie

/anoe; a oeeeea FOR oi?aaeaiea ia?aaeaaony ia oaa ?aeieoeeaee-

caoeee. (Iia?aoi? CONTINUE i?eiaiyaony oieueei a oeeeeao, ii ia

a ia?aeeth/aoaeyo. Iia?aoi? CONTINUE aioo?e ia?aeeth/aoaey

aioo?e oeeeea aucuaaao auiieiaiea neaaeothuae eoa?aoeee oeeeea).

A ea/anoaa i?eia?a i?eaaaeai o?aaiaio, eioi?ue ia?aaaou-

aaao oieueei iieiaeeoaeueiua yeaiaiou ianneaa a; io?eoeaoaeueiua

cia/aiey i?iioneathony.

FOR (I = 0; I 0)

IF (INDEX(LINE, “THE”) >= 0)

PRINTF(“%S”, LINE);

· 75 –

GETLINE(S, LIM) /* GET LINE INTO S, RETURN LENGTH *

CHAR S[];

INT LIM;

INT C, I;

I = 0;

WHILE(–LIM>0 && (C=GETCHAR()) != EOF && C != ‘N’)

S[I++] = C;

IF (C == ‘N’)

S[I++] = C;

S[I] = ‘0’;

RETURN(I);

INDEX(S,T) /* RETURN INDEX OF T IN S,-1 IF NONE */

CHAR S[], T[];

INT I, J, K;

FOR (I = 0; S[I] != ‘0’; I++)

FOR(J=I, K=0; T[K] !=’0′ && S[J] == T[K]; J++; K++)

;

IF (T[K] == ‘0’)

RETURN(I);

RETURN(-1);

Eaaeaeay ooieoeey eiaao aeae eiy (nienie a?aoiaioia, anee iie

eiathony) iienaiey a?aoiaioia, anee iie eiathony

iienaiey e iia?aoi?u , anee iie eiathony

Eae e oeacuaaaony, iaeioi?ua /anoe iiaoo ionoonoai-

aaoue; ieieiaeueiie ooieoeeae yaeyaony

DUMMY ()

eioi?ay ia niaa?oaao ieeaeeo aeaenoaee.

/Oaeay ie/aai ia aeaeathuay ooieoeey eiiaaea ieacuaaaony

oaeiaiie aeey nio?aiaiey ianoa aeey aeaeueiaeoaai ?acaeoey i?ia-

?aiiu/. anee ooieoeey aica?auaao /oi-eeai ioee/iia io oeaeiai

cia/aiey, oi ia?aae aa eiaiai iiaeao noiyoue oeacaoaeue oeia;

yoio aii?in ianoaeaeaaony a neaaeothuai ?acaeaea.

· 76 –

I?ia?aiiie yaeyaony i?inoi iaai? ii?aaeaeaiee ioaeaeueiuo

ooieoeee. Naycue iaaeaeo ooieoeeyie inouanoaeyaony /a?ac a?aoiai-

ou e aica?auaaiua ooieoeeyie cia/aiey /a yoii neo/aa/; aa

iiaeii oaeaea inouanoaeyoue /a?ac aiaoiea ia?aiaiiua. Ooieoeee

iiaoo ?aniieaaaoueny a enoiaeiii oaeea a ethaii ii?yaeea, a naia

enoiaeiay i?ia?aiia iiaeao ?aciauaoueny ia ianeieueeeo oaeeao,

ii oae, /oiau ie iaeia ooieoeey ia ?anuaieyeanue.

Iia?aoi? RETURN neoaeeo iaoaieciii aeey aica?auaiey cia-

/aiey ec aucaaiiie ooieoeee a ooieoeeth, eioi?ay e iae ia?aoe-

eanue. Ca RETURN iiaeao neaaeiaaoue ethaia au?aaeaiea:

RETURN (au?aaeaiea)

Aucuaathuay ooieoeey iiaeao eaii?e?iaaoue aica?auaaiia

cia/aiea, anee iia yoiai iiaeaeaao. Aieaa oiai, iinea RETURN

iiaeao ia auoue aiiaua ieeaeiai au?aaeaiey; a yoii neo/aa a au-

cuaathuoth i?ia?aiio ia ia?aaeaaony ieeaeiai cia/aiey. Oi?aaea-

iea oaeaea aica?auaony a aucuaathuoth i?ia?aiio aac ia?aaea/e

eaeiai-eeai cia/aiey e a oii neo/aa, eiaaea i?e auiieiaiee iu

“i?iaaeeaaainy” ia eiiaoe ooieoeee, aeinoeaay cae?uaathuaeny

i?aaie oeao?iie neiaee. ENee ooieoeey aica?auaao cia/aiea ec

iaeiiai ianoa e ia aica?auaao ieeaeiai cia/aiey ec ae?oaiai

ianoa, yoi ia yaeyaony iacaeiiiui, ii iiaeao auoue i?eciaeii

eaeeo-oi iai?eyoiinoae. A ethaii neo/aa “cia/aieai” ooieoeee,

eioi?ay ia aica?auaao cia/aiey, ianiiiaiii aoaeao ioni?. Io-

eaaei/iay i?ia?aiia LINT i?iaa?yao oaeea ioeaee.

Iaoaieea eiiieeyoeee e caa?ocee “C”-i?ia?aii, ?aniiei-

aeaiiuo a ianeieueeeo enoiaeiuo oaeeao, iaiyaony io nenoaiu e

nenoaia. A nenoaia “UNIX”, iai?eia?, yoo ?aaioo auiieiyao

eiiaiaea ‘CC’, oiiiyiooay a aeaaa 1. I?aaeiieiaeei, /oi o?e

ooieoeee iaoiaeyony a o?ao ?acee/iuo oaeeao n eiaiaie MAIN.n,

GETLINE.C e INDEX.n . Oiaaea eiiaiaea

CC MAIN.C GETLINE.C INDEX.C

eiiieee?oao yoe o?e oaeea, iiiauaao iieo/aiiue iano?aeaaaiue iauaeoiue
eiae a oaeeu MAIN.O, GETLINE.O e INDEX.O e caa?oaea-ao eo anao a
auiieiyaiue oaee, iacuaaaiue A.OUT .

Anee eiaaony eaeay-oi ioeaea, neaaeai a MAIN.C, oi yoio

oaee iiaeii ia?aeiiieee?iaaoue ioaeaeueii e caa?oceoue aianoa n

i?aaeuaeoueie iauaeoiuie oaeeaie ii eiiaiaea

CC MAIN.C GETLIN.O INDEX.O

Eiiaiaea ‘CC’ eniieuecoao niaeaoaiea i iaeiaiiaaiee n “.n” e “.i” aeey
oiai, /oiau ioee/eoue enoiaeiua oaeeu io iauaeoiuo.

Oi?aaeiaiea 4-1.

Ninoaaueoa i?ia?aiio aeey ooieoeee RINDEX(S,T), eioi?ay

aica?auaao iiceoeeth naiiai i?aaiai aoiaeaeaiey o a S e -1, anee

S ia niaea?aeeo T.

· 77 –

4.2. Ooieoeee, aica?auathuea iaoeaeua cia/aiey.

Aei neo ii? ie iaeia ec iaoeo i?ia?aii ia niaea?aeaea eaei-

ai-eeai iienaiey oeia ooieoeee. Aeaei a oii, /oi ii oiie/aieth

ooieoeey iayaii iienuaaaony naiei iiyaeaieai a au?aaeaiee eee

iia?aoi?a, eae, iai?eia?, a

WHILE (GETLINE(LINE, MAXLINE) > 0)

Anee iaeioi?ia eiy, eioi?ia ia auei iienaii ?aiaa, iiya-

eyaony a au?aaeaiee e ca iei neaaeoao eaaay e?oaeay neiaea, oi

iii ii eiioaenoo n/eoaaony eiaiai iaeioi?ie ooieoeee. E?iia

oiai, ii oiie/aieth i?aaeiieaaaaony, /oi yoa ooieoeey aica?aua-

ao cia/aiea oeia INT. Oae eae a au?aaeaieyo CHAR i?aia?acoao-

ny a INT, oi iao iaiaoiaeeiinoe iienuaaoue ooieoeee, aica?auath-

uea CHAR. Yoe i?aaeiieiaeaiey iie?uaatho aieueoeinoai neo/aaa,

aeeth/ay ana i?eaaaeaiiua aei neo ii? i?eia?u.

Ii /oi i?ienoiaeeo, anee ooieoeey aeieaeia aica?aoeoue cia/a-

iea eaeiai-oi ae?oaiai oeia ? Iiiaea /eneaiiua ooieoeee, oaeea

eae SQRT, SIN e COS aica?auatho DOUBLE; ae?oaea niaoeeaeueiua

ooieoeee aica?auatho cia/aiey ae?oaeo oeiia. *oiau iieacaoue,

eae iinooiaoue a yoii neo/aa, aeaaaeoa iaieoai e eniieuecoai

ooieoeeth ATiF(S), eioi?ay i?aia?acoao no?ieo S a yeaeaaeaio-

iia ae ieaaathuaa /enei aeaieiie oi/iinoe. Ooieoeey ATiF yaey-

aony ?anoe?aieai aoiI, aa?eaiou eioi?ie iu iaienaee a aeaaao

2 e 3; iia ia?aaaouaaao iaiaycaoaeueii ciae e aeanyoe/ioth oi/-

eo, a oaeaea oeaeoth e ae?iaioth /anoue, eaaeaeay ec eioi?uo iiaeao

eae i?enoonoaiaaoue, oae e ionoonoaiaaoue./yoa i?ioeaaeo?a i?a-

ia?aciaaiey aaiaea ia i/aiue aunieiai ea/anoaa; eia/a iia au

caiyea aieueoa ianoa, /ai iai oioaeinue au/.

Ai-ia?auo, naia ATiF aeieaeia iienuaaoue oei aica?auaaiiai

ath cia/aiey, iineieueeo ii ioee/ai io INT. Oae eae a au?aaea-

ieyo oei FLOAT i?aia?acoaony a DOUBLE, oi iao ieeaeiai niun-

ea a oii, /oiau ATOF aica?auaea FLOAT; iu iiaeai n ?aaiui on-

iaoii ainiieueciaaoueny aeiiieieoaeueiie oi/iinoueth, oae /oi iu

iieaaaai, /oi aica?auaaiia cia/aiea oeia DOUBLE. Eiy oeia

aeieaeii noiyoue ia?aae eiaiai ooieoeee, eae iieacuaaaony ieaea:

DOUBLE ATOF(S) /* CONVERT STRING S TO DOUBLE */

CHAR S[];

DOUBLE VAL, POWER;

INT I, SIGN;

· 78 –

FOR(I=0; S[I]==’ ‘ !! S[I]==’N’ !! S[I]==’T’; I++)

; /* SKIP WHITE SPACE */

SIGN = 1;

IF (S[I] == ‘+’ !! S[I] == ‘-‘) /* SIGN */

SIGN = (S[I++] == ‘+’) ? 1 : -1;

FOR (VAL = 0; S[I] >= ‘0’ && S[I] = ‘0’ && S[I] 0)

PRINTF(“T%.2FN”,SUM+=ATOF(LINE));

Ienaiea

DOUBLE SUM, ATOF();

aiai?eo, /oi SUM yaeyaony ia?aiaiiie oeia DOUBLE , e /oi

ATOF yaeyaony ooieoeeae, aica?auathuae cia/aiea oeia DOUBLE .

Yoa iiaiiieea icia/aao, /oi cia/aieyie eae SUM, oae e

ATOF(…) yaeythony ieaaathuea /enea aeaieiie oi/iinoe.

· 79 –

Anee ooieoeey ATOF ia aoaeao iienaia yaii a iaieo ianoao,

oi a “C” i?aaeiieaaaaony, /oi iia aica?auaao oeaeia cia/aiea,

e au iieo/eoa aanniuneaiiue ioaao. Anee naia ATOF e ia?aua-

iea e iae a MAIN eiatho ianiaianoeiua oeiu e iaoiaeyony a iae-

iii e oii aea oaeea, oi yoi aoaeao iaia?oaeaii eiiieeyoi?ii. Ii

anee ATOF auea neiiieee?iaaia ioaeaeueii //oi aieaa aa?iyoii/,

oi yoi ianiioaaonoaea ia aoaeao caoeene?iaaii, oae /oi ATOF

aoaeao aica?auaoue cia/aiey oeia DOUBLE, n eioi?ui MAIN aoaeao

ia?auaoueny, eae n INT , /oi i?eaaaeao e aanniuneaiiui ?acoeue-

oaoai. /I?ia?aiia LINT aueaaeeaaao yoo ioeaeo/.

Eiay ATOF, iu, a i?eioeeia, iiaee au n aa iiiiuueth iaie-

naoue ATOI (i?aia?aciaaiea no?iee a INT):

ATOI(S) /* CONVERT STRING S TO INTEGER */

CHAR S[];

DOUBLE ATOF();

RETURN(ATOF(S));

Ia?aoeoa aieiaiea ia no?oeoo?o iienaiee e iia?aoi? RETURN.

Cia/aiea au?aaeaiey a

RETURN (au?aaeaiea)

anaaaea i?aia?acoaony e oeio ooieoeee ia?aae auiieiaieai naiiai

aica?auaiey. Iiyoiio i?e iiyaeaiee a iia?aoi?a RETURN cia/a-

iea ooieoeee aoiF, eiathuaa oei DOUBLE, aaoiiaoe/anee i?aia?a-

coaony a INT, iineieueeo ooieoeey ATOI aica?auaao INT. (Eae

ianoaeaeaeinue a aeaaa 2, i?aia?aciaaiea cia/aiey n ieaaathuae

oi/eie e oeio INT inouanoaeyaony iin?aaenoaii ioa?anuaaiey

ae?iaiie /anoe).

Oi?aaeiaiea 4-2.

?anoe?ueoa ATOF oaeei ia?acii, /oiau iia iiaea ?aaioaoue n

/eneaie aeaea

123.45a-6

aaea ca /eneii n ieaaathuae oi/eie iiaeao neaaeiaaoue ‘E’ e iiea-

caoaeue yeniiiaiou, aiciiaeii ni ciaeii.

4.3. Aua ia a?aoiaioao ooieoeee.

A aeaaa 1 iu oaea ianoaeaeaee oio oaeo , /oi a?aoiaiou ooi-

eoeee ia?aaeathony ii cia/aieth, o.a. aucaaiiay ooieoeey iieo/aao

naith a?aiaiioth eiieth eaaeaeiai a?aoiaioa, a ia aai aae?an. yoi

icia/aao, /oi aucaaiiay ooieoeey ia iiaeao aicaeaenoaiaaoue ia

enoiaeiue a?aoiaio a aucuaathuae ooieoeee. Aioo?e ooieoeee eaae-

aeue a?aoiaio ii nouanoao yaeyaony eieaeueiie ia?aiaiiie, ei-

oi?ay eieoeeaeece?oaony oai cia/aieai, n eioi?ui e yoie ooie-

oeee ia?aoeeenue.

· 80 –

Anee a ea/anoaa a?aoiaioa ooieoeee aunooiaao eiy ianneaa,

oi ia?aaeaaony aae?an ia/aea yoiai ianneaa; naie yeaiaiou ia

eiie?othony. Ooieoeey iiaeao eciaiyoue yeaiaiou ianneaa, eniieue-

coy eiaeaenaoeeth e aae?an ia/aea. Oaeei ia?acii, iannea ia?aaea-

aony ii nnueea. A aeaaa 5 iu ianoaeei, eae eniieueciaaiea oea-

caoaeae iicaieyao ooieoeeyi aicaeaenoaiaaoue ia ioee/iua io

ianneaia ia?aiaiiua a aucuaathueo ooieoeeyo.

Iaaeaeo i?i/ei, ianouanoaoao iieiinoueth oaeiaeaoai?eoaeueiiai

niiniaa iaienaiey ia?aiineiie ooieoeee n ia?aiaiiui /eneii

a?aoiaioia. Aeaei a oii, /oi iao ia?aiineiiai niiniaa, n ii-

iiuueth eioi?iai aucaaiiay ooieoeey iiaea au ii?aaeaeeoue, neieue-

ei a?aoiaioia auei oaeoe/anee ia?aaeaii ae a aeaiiii ia?aua-

iee. Oaeei ia?acii, au, iai?eia?, ia iiaeaoa iaienaoue aeaeno-

aeoaeueii ia?aiineioth ooieoeeth, eioi?ay aoaeao au/eneyoue iaene-

ioi io i?iecaieueiiai /enea a?aoiaioia, eae aeaeatho ano?iaiiua

ooieoeee MAX a oi?o?aia e PL/1.

Iau/ii ni neo/aai ia?aiaiiiai /enea a?aoiaioia aaciianii

eiaoue aeaei, anee aucaaiiay ooieoeey ia eniieuecoao a?aoiaioia,

eioi?ua ae ia naiii aeaea ia auee ia?aaeaiu, e anee oeiu nia-

eanothony. Naiay ?ani?ino?aiaiiay a ycuea “C” ooieoeey n ia?a-

iaiiui /eneii – PRINTF . Iia iieo/aao ec ia?aiai a?aoiaioa

eioi?iaoeeth, iicaieythuoth ii?aaeaeeoue eiee/anoai inoaeueiuo a?-

aoiaioia e eo oeiu. Ooieoeey PRINTF ?aaioaao niaa?oaiii iai-

?aaeeueii, anee aucuaathuay ooieoeey ia?aaeaao ae iaaeinoaoi/iia

eiee/anoai a?aoiaioia, eee anee eo oeiu ia niaeanothony n oe-

iaie, oeacaiiuie a ia?aii a?aoiaioa. Yoa ooieoeey ia yaeyaony

ia?aiineiie e aeieaeia iiaeeoeoee?iaaoueny i?e eniieueciaaiee a

?acee/iuo oneiaeyo.

Anee aea oeiu a?aoiaioia ecaanoiu, oi eiiaoe nienea a?ao-

iaioia iiaeii ioiaoeoue, eniieuecoy eaeia-oi niaeaoaiea; iai?e-

ia?, n/eoay, /oi iaeioi?ia niaoeeaeueiia cia/aiea a?aoiaioa

(/anoi ioeue) yaeyaony i?eciaeii eiioea a?aoiaioia.

4.4. Aiaoiea ia?aiaiiua.

I?ia?aiia ia ycuea “C” ninoieo ec iaai?a aiaoieo iauae-

oia, eioi?ua yaeythony eeai ia?aiaiiuie, eeai ooieoeeyie. Oa?-

iei “aiaoiee” eniieuecoaony aeaaiui ia?acii a i?ioeaiiinoaa-

eaiea oa?ieio “aioo?aiiee”, eioi?ui iienuaathony a?aoiaiou e

aaoiiaoe/aneea ia?aiaiiua, ii?aaeaeaiiua aio?oe ooieoeee.

Aiaoiea ia?aiaiiua ii?aaeaeaiu aia eaeie-eeai ooieoeee e, oa-

eei ia?acii, iioaioeeaeueii aeinooiiu aeey iiiaeo ooieoeee. Naie

ooieoeee anaaaea yaeythony aiaoieie, iioiio /oi i?aaeea ycuea

“C” ia ?ac?aoatho ii?aaeaeyoue iaeie ooieoeee aioo?e ae?oaeo. Ii

oiie/aieth aiaoiea ia?aiaiiua yaeythony oaeaea e “aeiaaeueiuie”,

oae /oi ana nnueee ia oaeoth ia?aiaiioth, eniieuecothuea iaeii e

oi aea eiy (aeaaea ec ooieoeee, neiiieee?iaaiiuo iacaaeneii),

aoaeoo nnueeaie ia iaeii e oi aea. A yoii niunea aiaoiea ia?a-

iaiiua aiaeiae/iu ia?aiaiiui COiMON a oi?o?aia e EXTERNAL a

PL/1. Iicaeiaa iu iieaaeai, eae ii?aaeaeeoue aiaoiea ia?aiaiiua

e ooieoeee oaeei ia?acii, /oiau iie auee aeinooiiu ia aeiaaeue-

ii, a oieueei a i?aaeaeao iaeiiai enoiaeiiai oaeea.

· 81 –

A neeo naiae aeiaaeueiie aeinooiiinoe aiaoiea ia?aiaiiua

i?aaeinoaaeytho ae?oaoth, ioee/ioth io a?aoiaioia e aica?auaaiuo

cia/aiee, aiciiaeiinoue aeey iaiaia aeaiiuie iaaeaeo ooieoeeyie.

Anee eiy aiaoiae ia?aiaiiie eaeei-eeai ia?acii iienaii, oi

ethaay ooieoeey eiaao aeinooi e yoie ia?aiaiiie, nnueaynue e iae

ii yoiio eiaie.

A neo/ayo, eiaaea naycue iaaeaeo ooieoeeyie inouanoaeyaony n

iiiiuueth aieueoiai /enea ia?aiaiiuo, aiaoiea ia?aiaiiua ieacu-

aathony aieaa oaeiaiuie e yooaeoeaiuie, /ai eniieueciaaiea

aeeeiiuo nieneia a?aoiaioia. Eae, iaeiaei, ioia/aeinue a aeaaa

1, yoi niia?aaeaiea neaaeoao eniieueciaaoue n ii?aaeaeaiiie inoi-

?iaeiinoueth, oae eae iii iiaeao ieioi io?aceoueny ia no?oeoo?a

i?ia?aii e i?eaiaeeoue e i?ia?aiiai n aieueoei /eneii naycae ii

aeaiiui iaaeaeo ooieoeeyie.

Aoi?ay i?e/eia eniieueciaaiey aiaoieo ia?aiaiiuo naycaia

n eieoeeaeecaoeeae. A /anoiinoe, aiaoiea ianneau iiaoo auoue

eieoeeaeece?iaaiu a aaoiiaoe/aneea iao. Iu ?anniio?ei aii?in

ia eieoeeaeecaoeee a eiioea yoie aeaau.

O?aouey i?e/eia eniieueciaaiey aiaoieo ia?aiaiiuo iaoneia-

eaia eo iaeanoueth aeaenoaey e a?aiaiai nouanoaiaaiey. Aaoiia-

oe/aneea ia?aiaiiua yaeythony aioo?aiieie ii ioiioaieth e ooi-

eoeeyi; iie aicieeatho i?e aoiaea a ooieoeeth e en/acatho i?e au-

oiaea ec iaa. Aiaoiea ia?aiaiiua, iai?ioea, nouanoaotho iinoi-

yiii. Iie ia iiyaeythoy e ia en/acatho, oae /oi iiaoo nio?a-

iyoue naie cia/aiey a ia?eiae io iaeiiai ia?auaiey e ooieoeee aei

ae?oaiai. A neeo yoiai, anee aeaa ooieoeee eniieuecotho iaeioi?ua

iauea aeaiiua, i?e/ai ie iaeia ec ieo ia ia?auaaony e ae?oaie ,

oi /anoi iaeaieaa oaeiaiui ieacuaaaony o?aieoue yoe iauea aeai-

iua a aeaea aiaoieo ia?aiaiiuo, a ia ia?aaeaaaoue eo a ooieoeeth

e ia?aoii n iiiiuueth a?aoiaioia.

Aeaaaeoa i?iaeieaeei ianoaeaeaiea yoiai aii?ina ia aieueoii

i?eia?a. Caaea/a aoaeao ninoiyoue a iaienaiee ae?oaie i?ia?aiiu

aeey eaeueeoeyoi?a, eo/oae,/ai i?aaeuaeouay. Caeanue aeiioneathony

iia?aoeee +,-,*,/ e ciae = (aeey auaea/e ioaaoa).aianoi eioeen-

iiai i?aaenoaaeaiey eaeueeoeyoi? aoaeao eniieueciaaoue ia?aoioth

iieueneoth iioaoeeth,iineieueeo aa ianeieueei eaa/a ?aaeeciaaoue.a

ia?aoiie iieueneie iioaoeee ciae neaaeoao ca iia?aiaeaie; eioee-

niia au?aaeaiea oeia

(1-2)*(4+5)=

caienuaaaony a aeaea

12-45+*=

e?oaeua neiaee i?e yoii ia ioaeiu

· 82 –

?aaeecaoeey ieacuaaaony aanueia i?inoie.eaaeaeue iia?aiae ii-

iauaaony a noae; eiaaea iinooiaao ciae iia?aoeee,ioaeiia /enei

iia?aiaeia (aeaa aeey aeia?iuo iia?aoeee) auieiaaony,e iei i?e-

iaiyaony iia?aoeey e ?acoeueoao iai?aaeyaony ia?aoii a

noae.oae a i?eaaaeaiiii auoa i?eia?a 1 e 2 iiiauathony a noae

e caoai caiaiythony eo ?aciinoueth, -1.iinea yoiai 4 e 5 aai-

aeyony a noae e caoai caiaiythony naiae noiiie,9.aeaeaa /enea

· 1 e 9 caiaiythony a noaea ia eo i?iecaaaeaiea,?aaiia -9.iia-?aoeey =
ia/aoaao aa?oiee yeaiaio noaea, ia oaeaeyy aai (oae /oi i?iiaaeooi/iua
au/eneaiey iiaoo auoue i?iaa?aiu).

Naie iia?aoeee iiiauaiey /enae a noae e eo ecaea/aiey

i/aiue i?inou,ii, a nayce n aeeth/aieai a ianoiyuoth i?ia?aiio

iaia?oaeaiey ioeaie e ainnoaiiaeaiey,iie ieacuaathony aeinoa-

oi/ii aeeeiiuie. Iiyoiio eo/oa ioi?ieoue eo a aeaea ioaeaeueiuo

ooieoeee,/ai iiaoi?youe niioaaonoaothuee oaeno iianthaeo a i?ia-

?aiia. E?iia oiai, ioaeia ioaeaeueiay ooieoeey aeey auai?ee ec

aaiaea neaaeothuae iia?aoeee eee iia?aiaea. Oaeei ia?acii, no?oe-

oo?a i?ia?aiiu eiaao aeae:

WHILE( iinooiaao iia?aoeey eee iia?aiae, a ia eiiaoe

IF ( /enei )

iiianoeoue aai a noae

aLSE IF ( iia?aoeey )

auiooue iia?aiaeu ec noaea

auiieieoue iia?aoeeth

iiianoeoue ?acoeueoao a noae

ELSE

ioeaea

Iniiaiie aii?in, eioi?ue aua ia aue ianoaeaeai, caeeth/aao-

ny a oii,aaea iiianoeoue noae, o. A. Eaeea i?ioeaaeo?u niiaoo

ia?auaoueny e iaio iaiin?aaenoaaiii. Iaeia ec oaeeo aiciiaeiin-

oae ninoieo a iiiauaiee noaea a MAIN e ia?aaea/e naiiai noaea

e oaeouae iiceoeee a noaea ooieoeeyi, ?aaioathuei ni noaeii. Ii

ooieoeee MAIN iao iaiaoiaeeiinoe eiaoue aeaei n ia?aiaiiuie, oi-

?aaeythueie noaeii; ae anoanoaaiii ?annoaeaeaoue a oa?ieiao ii-

iauaiey /enae a noae e ecaea/aiey eo ioooaea. A neeo yoiai iu

?aoeee naeaeaoue noae e naycaiioth n iei eioi?iaoeeth aiaoieie

ia?aiaiiuie , aeinooiiuie ooieoeeyi PUSH (iiiauaiea a noae) e

POP (ecaea/aiea ec noaea), ii ia MAIN.

Ia?aaiae yoie noaiu a i?ia?aiio aeinoaoi/ii i?ino. Aaaeouay

i?ia?aiia yaeyaony ii nouanoao aieueoei ia?aeeth/aoaeai ii oe-

io iia?aoeee eee iia?aiaeo; yoi, ii-aeaeeiiio, aieaa oa?aeoa?-

iia i?eiaiaea ia?aeeth/aoaey, /ai oi, eioi?ia auei i?iaeaiiin-

o?e?iaaii a aeaaa 3.

#DEFINE MAXOP 20 /* MAX SIZE OF OPERAND, OPERATOR *

#DEFINE NUMBER ‘0’ /* SIGNAL THAT NUMBER FOUND */

#DEFINE TOOBIG ‘9’ /* SIGNAL THAT STRING IS TOO BIG *

· 83 –

MAIN() /* REVERSE POLISH DESK CALCULATOR */

/(

INT TUPE;

CHAR S[MAXOP];

DOUBLE OP2,ATOF(),POP(),PUSH();

WHILE ((TUPE=GETOP(S,MAXOP)) !=EOF);

SWITCH(TUPE) /(

CASE NUMBER:

PUSH(ATOF(S));

BREAK;

CASE ‘+’:

PUSH(POP()+POP());

BREAK;

CASE ‘*’:

PUSH(POP()*POP());

BREAK;

CASE ‘-‘:

OP2=POP();

PUSH(POP()-OP2);

BREAK;

CASE ‘/’:

OP2=POP();

IF (OP2 != 0.0)

PUSH(POP()/OP2);

ELSE

PRINTF(“ZERO DIVISOR POPPEDN”);

BREAK;

CASE ‘=’:

PRINTF(“T%FN”,PUSH(POP()));

BREAK;

CASE ‘C’:

CLEAR();

BREAK;

CASE TOOBIG:

PRINTF(“%.20S … IS TOO LONGN”,S)

BREAK;

/)

/)

#DEFINE MAXVAL 100 /* MAXIMUM DEPTH OF VAL STACK */

· 84 –

INT SP = 0; /* STACK POINTER */

DOUBLE VAL[MAXVAL]; /*VALUE STACK */

DOUBLE PUSH(F) /* PUSH F ONTO VALUE STACK */

DOUBLE F;

/(

IF (SP 0)

RETURN(VAL[–SP]);

ELSE /(

PRINTF(“ERROR: STACK EMPTYN”);

CLEAR();

RETURN(0);

/)

/)

CLEAR() /* CLEAR STACK */

/(

SP=0;

/)

Eiiaiaea C i/euaao noae n iiiiuueth ooieoeee CLEAR, eioi?ay

oaeaea eniieuecoaony a neo/aa ioeaee ooieoeeyie PUSH e POP. e

ooieoeee GETOP iu i/aiue nei?i aa?iainy.

Eae oaea aiai?eeinue a aeaaa 1, ia?aiaiiay yaeyaony aiao-

iae, anee iia ii?aaeaeaia aia oaea eaeie au oi ie auei ooie-

oeee. Iiyoiio noae e oeacaoaeue noaea, eioi?ua aeieaeiu eniieue-

ciaaoueny ooieoeeyie PUSH, POP e CLEAR, ii?aaeaeaiu aia yoeo

o?ao ooieoeee. Ii naia ooieoeey MAIN ia nnueaaony ie e noaeo,

ie e oeacaoaeth noaea – eo o/anoea ouaoaeueii caianee?iaaii. A

neeo yoiai /anoue i?ia?aiiu, niioaaonoaothuay iia?aoeee = , en-

iieuecoao eiino?oeoeeth

PUSH(POP());

aeey oiai, /oiau i?iaiaeece?iaaoue aa?oiee yeaiaio noaea, ia

eciaiyy aai.

Ioiaoei oaeaea, /oi oae eae iia?aoeee + e * eiiiooaoeaiu,

ii?yaeie, a eioi?ii iauaaeeiythony ecaea/aiiua iia?aiaeu, iano-

uanoaaiai, ii a neo/aa iia?aoeee – e / iaiaoiaeeii ?acee/aoue

eaaue e i?aaue iia?aiaeu.

· 85 –

Oi?aaeiaiea 4-3.

I?eaaaeaiiay iniiaiay noaia aeiioneaao iaiin?aaenoaaiiia

?anoe?aiea aiciiaeiinoae eaeueeoeyoi?a. Aeeth/eoa iia?aoeeth aea-

eaiey ii iiaeoeth /%/ e oia?iue ieion. Aeeth/eoa eiiaiaeo “noa-

?aoue”, eioi?ay oaeaeyao aa?oiee yeaiaio noaea. Aaaaeeoa eiiai-

aeu aeey ?aaiou n ia?aiaiiuie. /Yoi i?inoi, anee eiaia ia?a-

iaiiuo aoaeoo ninoiyoue ec iaeiie aoeau ec eiathueony aeaaaeoeaoe

oanoe aoea/.

4.5. I?aaeea, ii?aaeaeythuea iaeanoue aeaenoaey.

Ooieoeee e aiaoiea ia?aiaiiua, aoiaeyuea a ninoaa

“C”-i?ia?aiiu, ia iaycaiu eiiieee?iaaoueny iaeiia?aiaiii;

i?ia?aiia ia enoiaeiii ycuea iiaeao ?aniieaaaoueny a ianeieueeeo

oaeeao, e ?aiaa neiiieee?iaaiiua i?ioeaaeo?u iiaoo caa?oaeaoueny

ec aeaeeioae. Aeaa aii?ina i?aaenoaaeytho eioa?an:

Eae neaaeoao ninoaaeyoue iienaiey, /oiau ia?aiaiiua i?a-

aeeueii aini?eieiaeenue ai a?aiy eiiieeyoeee ?

Eae neaaeoao ninoaaeyoue iienaiey, /oiau iaania/eoue i?a-

aeeueioth naycue /anoae i?ia?aiiu i?e caa?ocea ?

4.5.1. Iaeanoue aeaenoaey.

Iaeanoueth aeaenoaey eiaie yaeyaony oa /anoue i?ia?aiiu, a

eioi?ie yoi eiy ii?aaeaeaii. Aeey aaoiiaoe/aneie ia?aiaiiie,

iienaiiie a ia/aea ooieoeee, iaeanoueth aeaenoaey yaeyaony oa

ooieoeey, a eioi?ie iienaii eiy yoie ia?aiaiiie, a ia?aiaiiua

ec ?aciuo ooieoeee, eiathuea iaeeiaeiaia eiy, n/eoathony ia io-

iinyueieny ae?oa e ae?oao. Yoi aea ni?aaaaeeeai e aeey a?aoiaioia

ooieoeee.

Iaeanoue aeaenoaey aiaoiae ia?aiaiiie i?inoe?aaony io oi/-

ee, a eioi?ie iia iauyaeaia a enoiaeiii oaeea, aei eiioea yoiai

oaeea. Iai?eia?, anee VAL, SP, PUSH, POP e CLEAR ii?aaeaeaiu

a iaeiii oaeea a ii?yaeea, oeacaiiii auoa, a eiaiii:

INT SP = 0;

DOUBLE VAL[MAXVAL];

DOUBLE PUSH(F) …

DOUBLE POP() …

CLEAR() …

oi ia?aiaiiua VAL e SP iiaeii eniieueciaaoue a PUSH, POP e

CLEAR i?yii ii eiaie; ieeaeea aeiiieieoaeueiua iienaiey ia

ioaeiu.

N ae?oaie noi?iiu, anee ioaeii nineaoueny ia aiaoithth ia?a-

iaiioth aei aa ii?aaeaeaiey, eee anee oaeay ia?aiaiiay ii?aaea-

eaia a oaeea, ioee/iii io oiai, a eioi?ii iia eniieuecoaony,

oi iaiaoiaeeii iienaiea EXTERN.

· 86 –

Aaaeii ?acee/aoue iienaiea aiaoiae ia?aiaiiie e aa ii?aaea-

eaiea. iienaiea oeacuaaao naienoaa ia?aiaiiie /aa oei, ?ac-

ia? e o.ae./; ii?aaeaeaiea aea aucuaaao aua e ioaaaeaiea iaiyoe.

Anee aia eaeie au oi ie auei ooieoeee iiyaeythony no?i/ee

INT SP;

DOUBLE VAL[MAXVAL];

oi iie ii?aaeaeytho aiaoiea ia?aiaiiua SP e VAL, aucuaatho io-

aaaeaiea iaiyoe aeey ieo e neoaeao a ea/anoaa iienaiey aeey in-

oaeueiie /anoe yoiai enoiaeiiai oaeea. A oi aea a?aiy no?i/ee

EXTERN INT SP;

EXTERN DOUBLE VAL[];

iienuaatho a inoaeueiie /anoe yoiai enoiaeiiai oaeea ia?aiaiioth

SP eae INT, a VAL eae iannea oeia DOUBLE /?acia? eioi?iai

oeacai a ae?oaii ianoa/, ii ia nicaeatho ia?aiaiiuo e ia ioai-

aeyo ei ianoa a iaiyoe.

Ai anao oaeeao, ninoaaeythueo enoiaeioth i?ia?aiio, aeieaeii

niaea?aeaoueny oieueei iaeii ii?aaeaeaiea aiaoiae ia?aiaiiie; ae?o-

aea oaeeu iiaoo niaea?aeaoue iienaiey EXTERN aeey aeinooia e iae.

/Iienaiea EXTERN iiaeao eiaoueny e a oii oaeea, aaea iaoiaeeony

ii?aaeaeaiea/. Ethaay eieoeeaeecaoeey aiaoiae ia?aiaiiie i?iai-

aeeony oieueei a ii?aaeaeaiee. A ii?aaeaeaiee aeieaeiu oeacuaaoueny

?acia?u ianneaia, a a iienaiee EXTERN yoiai iiaeii ia aeaeaoue.

Oioy iiaeiaiay i?aaiecaoeey i?eaaaeaiiie auoa i?ia?aiiu e

iaeiaa?iyoia, ii VAL e SP iiaee au auoue ii?aaeaeaiu e eieoeea-

eece?iaaiu a iaeiii oaeea, a ooieoeey PUSH, POP e CLEAR ii?a-

aeaeaiu a ae?oaii. A yoii neo/aa aeey nayce auee au iaiaoiaeeiu

neaaeothuea ii?aaeaeaiey e iienaiey:

a oaeea 1:

INT SP = 0; /* STACK POINTER */

DOUBLE VAL[MAXVAL]; /* VALUE STACK */

a oaeea 2:

EXTERN INT SP;

EXTERN DOUBLE VAL[];

DOUBLE PUSH(F) …

DOUBLE POP() …

CLEAR() …

oae eae iienaiey EXTERN ‘a oaeea 1’ iaoiaeyony auoa e aia

o?ao oeacaiiuo ooieoeee, iie ioiinyony ei anai iei; iaeiiai

iaai?a iienaiee aeinoaoi/ii aeey anaai ‘oaeea 2′.

· 87 –

Aeey i?ia?aii aieueoiai ?acia?a ianoaeaeaaiay iicaea a yoie

aeaaa aiciiaeiinoue aeeth/aiey oaeeia, #INCLUDE, iicaieyao

eiaoue ai anae i?ia?aiia oieueei iaeio eiieth iienaiee EXTERN e

anoaaeyoue aa a eaaeaeue enoiaeiue oaee ai a?aiy aai eiiieeyoeee.

Ia?aoeiny oaia?ue e ooieoeee GETOP, auae?athuae ec oaeea

aaiaea neaaeothuoth iia?aoeeth eee iia?aiae. Iniiaiay caaea/a i?in-

oa: i?iionoeoue i?iaaeu, ciaee oaaoeyoeee e iiaua no?iee. Anee

neaaeothuee neiaie ioee/ai io oeeo?u e aeanyoe/iie oi/ee, oi

aica?aoeoue aai. A i?ioeaiii neo/aa nia?aoue no?ieo oeeo? /iia

iiaeao aeeth/aoue aeanyoe/ioth oi/eo/ e aica?aoeoue NUMBER eae

neaiae i oii, /oi aua?aii /enei.

I?ioeaaeo?a nouanoaaiii oneiaeiyaony, anee no?aieoueny i?a-

aeeueii ia?aaaouaaoue neooaoeeth, eiaaea aaiaeeiia /enei ieacuaa-

aony neeoeii aeeeiiui. Ooieoeey GETOP n/eouaaao oeeo?u iiae?yae

/aiciiaeii n aeanyoe/iie oi/eie/ e caiiieiaao eo, iiea iinea-

aeiaaoaeueiinoue ia i?a?uaaaony. Anee i?e yoii ia i?ienoiaeeo

ia?aiieiaiey, oi ooieoeey aica?auaao NUMBER e no?ieo oeeo?.

Anee aea /enei ieacuaaaony neeoeii aeeeiiui, oi GETOP ioa?anu-

aaao inoaeueioth /anoue no?iee ec oaeea aaiaea, oae /oi iieueci-

aaoaeue iiaeao i?inoi ia?aia/aoaoue yoo no?ieo n ianoa ioeaee;

ooieoeey aica?auaao TOOBIG eae neaiae i ia?aiieiaiee.

GETOP(S, LIM) /* GET NEXT OPRERATOR OR OPERAND */

CHAR S[];

INT LIM;

INT I, C;

WHILE((C=GETCH())==’ ‘!! C==’T’ !! C==’N’)

;

IF (C != ‘.’ && (C ‘9’))

RETURN©;

S[0] = C;

FOR(I=1; (C=GETCHAR()) >=’0′ && C =’0′ && C 0) ? BUF[–BUFP] : GETCHAR());

UNGETCH© /* PUSH CHARACTER BACK ON INPUT */

INT C;

IF (BUFP > BUFSIZE)

PRINTF(“UNGETCH: TOO MANY CHARACTERSN”);

ELSE

BUF [BUFP++] = C;

Iu eniieueciaaee aeey o?aiaiey aica?auaaiuo neiaieia iannea, a

ia ioaeaeueiue neiaie, iioiio /oi oaeay iauiinoue iiaeao i?eai-

aeeoueny a aeaeueiaeoai.

· 89 –

Oi?aaeiaiea 4-4.

Iaieoeoa ooieoeeth UNGETS(S) , eioi?ay aoaeao aica?auaoue ai

aaiae oeaeoth no?ieo. Aeieaeia ee UNGETS eiaoue aeaei n BUF e BUFP

eee iia iiaeao i?inoi eniieueciaaoue UNGETCH ?

Oi?aaeiaiea 4-5.

I?aaeiieiaeeoa, /oi iiaeao aica?auaoueny oieueei iaeei neiaie. Ec-

iaieoa GETCH e UNGETCH niioaaonoaothuei ia?acii.

Oi?aaeiaiea 4-6.

Iaoe ooieoeee GETCH e UNGETCH ia iaania/eaatho ia?aaioeo aica-

?auaiiiai neiaiea EOF ia?aiineiui ia?acii. ?aoeoa, eaeei

naienoaii aeieaeiu iaeaaeaoue yoe ooieoeee, anee aica?auaaony

EOF, e ?aaeecoeoa aaoe auaiaeu.

4.6. Noaoe/aneea ia?aiaiiua.

Noaoe/aneea ia?aiaiiua i?aaenoaaeytho niaie o?aoee eeann

iaiyoe, a aeiiieiaiee e aaoiiaoe/aneei ia?aiaiiui e EXTERN, n

eioi?uie iu oaea ano?a/aeenue.

Noaoe/aneea ia?aiaiiua iiaoo auoue eeai aioo?aiieie, eeai

aiaoieie. Aioo?aiiea noaoe/aneea ia?aiaiiua oi/ii oae aea,

eae e aaoiiaoe/aneea, yaeythony eieaeueiuie aeey iaeioi?ie ooi-

eoeee, ii, a ioee/ea io aaoiiaoe/aneeo, iie inoathony nouano-

aiaaoue, a ia iiyaeythony e en/acatho aianoa n ia?auaieai e

yoie ooieoeee. yoi icia/aao, /oi aioo?aiiea noaoe/aneea ia?a-

iaiiua iaania/eaatho iinoiyiiia, iaaeinooiiia ecaia o?aiaiea

aioo?e ooieoeee. Neiaieueiua no?iee, iiyaeythueany aioo?e ooie-

oeee, eae, iai?eia?, a?aoiaiou PRINTF , yaeythony aioo?aiieie

noaoe/aneeie.

Aiaoiea noaoe/aneea ia?aiaiiua ii?aaeaeaiu a inoaeueiie

/anoe oiai enoiaeiiai oaeea, a eioi?ii iie iienaiu, ii ia a

eaeii-eeai ae?oaii oaeea. Oaeei ia?acii, iie aeatho niinia

ne?uaaoue eiaia, iiaeiaiua BUF e BUFP a eiiaeiaoeee

GETCH-UNGETCH, eioi?ua a neeo eo niaianoiiai eniieueciaaiey

aeieaeiu auoue aiaoieie, ii ana aea ia aeinooiiuie aeey iieueciaa-

oaeae GETCH e UNGETCH , /oiau eneeth/aeanue aiciiaeiinoue eiio-

eeeoa. Anee yoe aeaa ooieoeee e aeaa ia?aiaiiua iauaaeaieoue a

iaeiii oaeea neaaeothuei ia?acii

STATIC CHAR BUF[BUFSIZE]; /* BUFFER FOR UNGETCH */

STATIC INT BUFP=0; /*NEXT FREE POSITION IN BUF */

GETCH() …

UNGETCH() …

oi ieeaeay ae?oaay ooieoeey ia aoaeao a ninoiyiee ia?aoeoueny e

BUF e BUFP; oaeoe/anee, iie ia aoaeoo anooiaoue a eiioeeeo n

oaeeie aea eiaiaie ec ae?oaeo oaeeia oie aea naiie i?ia?aiiu.

Noaoe/aneay iaiyoue, eae aioo?aiiyy, oae e aiaoiyy, nia-

oeeoeoee?oaony neiaii STATIC , noiyuei ia?aae iau/iui iienaie-

ai. Ia?aiaiiay yaeyaony aiaoiae, anee iia iienaia aia eaeie

au oi ie auei ooieoeee, e aioo?aiiae, anee iia iienaia aioo?e

iaeioi?ie ooieoeee.

· 90 –

Ii?iaeueii ooieoeee yaeythony aiaoieie iauaeoaie; eo eiaia

ecaanoiu aeiaaeueii. aiciiaeii, iaeiaei, iauyaeoue ooieoeeth eae

STATIC ; oiaaea aa eiy noaiiaeony iaecaanoiui aia oaeea, a

eioi?ii iii iienaii.

A ycuea “C” “STATIC” io?aaeaao ia oieueei iinoiyinoai, ii

e noaiaiue oiai, /oi iiaeii iacaaoue “i?eaaoiinoueth”. Aioo?aiiea

noaoe/aneea iauaeou ii?aaeaeaiu oieueei aioo?e iaeiie ooieoeee;

aiaoiea noaoe/aneea iauaeou /ia?aiaiiua eee ooieoeee/ ii?aaea-

eaiu oieueei aioo?e oiai enoiaeiiai oaeea, aaea iie iiyaeythony,

e eo eiaia ia anooiatho a eiioeeeo n oaeeie aea eiaiaie ia?a-

iaiiuo e ooieoeee ec ae?oaeo oaeeia.

Aiaoiea noaoe/aneea ia?aiaiiua e ooieoeee i?aaeinoaaeytho

niinia i?aaieciauaaoue aeaiiua e ?aaioathuea n ieie aioo?aiiea

i?ioeaaeo?u oaeei ia?acii, /oi ae?oaea i?ioeaaeo?u e aeaiiua ia

iiaoo i?eeoe n ieie a eiioeeeo aeaaea ii iaaei?acoiaieth. Iai?e-

ia?, ooieoeee GETCH e UNGETCH ia?acotho “iiaeoeue” aeey aaiaea e

aica?auaiey neiaieia; BUF e BUFP aeieaeiu auoue noaoe/aneeie,

/oiau iie ia auee aeinooiiu ecaia. Oi/ii oae aea ooieoeee PUSH,

POP e CLEAR oi?ie?otho iiaeoeue ia?aaioee noaea; VAR e SP oiaea

aeieaeiu auoue aiaoieie noaoe/aneeie.

4.7. ?aaeno?iaua ia?aiaiiua.

*aoaa?oue e iineaaeiee eeann iaiyoe iacuaaaony ?aaeno?i-

aui. Iienaiea REGISTER oeacuaaao eiiieeyoi?o, /oi aeaiiay ia-

?aiaiiay aoaeao /anoi eniieueciaaoueny. Eiaaea yoi aiciiaeii, ia-

?aiaiiua, iienaiiua eae REGISTER, ?aniieaaathony a iaoeiiuo

?aaeno?ao, /oi iiaeao i?eaanoe e iaiueoei ii ?acia?o e aieaa

auno?ui i?ia?aiiai. Iienaiea REGISTER auaeyaeeo eae

REGISTER INT X;

REGISTER CHAR C;

e o.ae.; /anoue INT iiaeao auoue iiouaia. Iienaiea REGISTER iiae-

ii eniieueciaaoue oieueei aeey aaoiiaoe/aneeo ia?aiaiiuo e oi?-

iaeueiuo ia?aiao?ia ooieoeee. A yoii iineaaeiai neo/aa iienaiey

auaeyaeyo neaaeothuei ia?acii:

F(C,N)

REGISTER INT C,N;

REGISTER INT I;

· 91 –

Ia i?aeoeea aicieeatho iaeioi?ua ia?aie/aiey ia ?aaeno?i-

aua ia?aiaiiua, io?aaeathuea ?aaeueiua aiciiaeiinoe eiathueony

aiia?aoiuo n?aaenoa. A ?aaeno?u iiaeii iiianoeoue oieueei ian-

eieueei ia?aiaiiuo a eaaeaeie ooieoeee, i?e/ai oieueei ii?aaeaeai-

iuo oeiia. A neo/aa i?aauoaiey aiciiaeiiai /enea eee eniieue-

ciaaiey ia?ac?aoaiiuo oeiia neiai REGISTER eaii?e?oaony.

E?iia oiai iaaiciiaeii ecaea/ue aae?an ?aaeno?iaie ia?aiaiiie

(yoio aii?in ianoaeaeaaony a aeaaa 5). Yoe niaoeeoe/aneea ia?a-

ie/aiey aa?uee?othony io iaoeiu e iaoeia. Oae, iai?eia?, ia

PDP-11 yooaeoeaiuie yaeythony oieueei ia?aua o?e iienaiey

REGISTER a ooieoeee, a a ea/anoaa oeiia aeiioneathony INT, CHAR

eee oeacaoaeue.

4.8. Aei/iay no?oeoo?a.

sscue “C” ia yaeyaony ycueii n aei/iie no?oeoo?ie a niun-

ea PL/1 eee aeaiea; a iai iaeuecy iienuaaoue iaeie ooieoeee

aioo?e ae?oaeo.

Ia?aiaiiua aea, n ae?oaie noi?iiu, iiaoo ii?aaeaeyoueny ii

iaoiaeo aei/iiai no?oeoo?e?iaaiey. Iienaiey ia?aiaiiuo (aeeth-

/ay eieoeeaeecaoeeth) iiaoo neaaeiaaoue ca eaaie oeao?iie neia-

eie,ioe?uaathuae ethaie iia?aoi?, a ia oieueei ca oie, n eioi-

?ie ia/eiaaony oaei ooieoeee. Ia?aiaiiua, iienaiiua oaeei ia-

?acii, auoaniytho ethaua ia?aiaiiua ec aiaoieo aeieia, eiathuea

oaeea aea eiaia, e inoathony ii?aaeaeaiiuie aei niioaaonoaothuae

i?aaie oeao?iie neiaee. Iai?eia? a

IF (N > 0)

INT I; /* DECLARE A NEW I */

FOR (I = 0; I 0); /* DISCARD IT */

WHILE (–I >= 0)

PUTCHAR(S[I]);

Aeueoa?iaoeaie yoiio niiniao yaeyaony ?aeo?neaiia ?aoa-

iea, eiaaea i?e eaaeaeii auciaa ooieoeey PRINTD nia/aea niiaa

ia?auaaony e naaa, /oiau neiie?iaaoue eeaee?othuea oeeo?u, a ca-

oai ia/aoaao iineaaeithth oeeo?o.

PRINTD(N) /* PRINT N IN DECIMAL (RECURSIVE)*/

INT N;

(

INT I;

IF (N 0) THEN

BEGIN

A = 1;

B = 2

END

Eiaaony oaeaea aiciiaeiinoue ii?aaeaeaiey iae?ina n a?aoiai-

oaie, oae /oi caiaiythuee oaeno aoaeao caaenaoue io aeaea ia?a-

uaiey e iae?ino. Ii?aaeaeei, iai?eia?, iae?in n eiaiai MAX

neaaeothuei ia?acii:

#DEFINE MAX(A, B) ((A) > (B) ? (A) : (B))

eiaaea no?iea

X = MAX(P+Q, R+S);

aoaeao caiaiaia no?ieie

X = ((P+Q) > (R+S) ? (P+Q) : (R+S));

Oaeay aiciiaeiinoue iaania/eaaao “ooieoeeth iaeneioia”, eioi?ay

?anoe?yaony a iineaaeiaaoaeueiue eiae, a ia a ia?auaiea e ooie-

oeee. I?e i?aaeeueiii ia?auaiee n a?aoiaioaie oaeie iae?in ao-

aeao ?aaioaoue n ethauie oeiaie aeaiiuo; caeanue iao iaiaoiaeeiinoe

a ?acee/iuo aeaeao MAX aeey aeaiiuo ?aciuo oeiia, eae yoi auei

au n ooieoeeyie.

· 97 –

Eiia/ii, anee au ouaoaeueii ?anniio?eoa i?eaaaeaiiia auoa

?anoe?aiea MAX, au caiaoeoa ii?aaeaeaiiua iaaeinoaoee. Au?aaea-

iey au/eneythony aeaaaeaeu; yoi ieioi, anee iie aeaeoo ca niaie

iiai/iua yooaeou, aucaaiiua, iai?eia?, ia?auaieyie e ooieoee-

yi eee eniieueciaaieai iia?aoeee oaaee/aiey. Ioaeii iicaaioeoue-

ny i i?aaeeueiii eniieueciaaiee e?oaeuo neiaie, /oiau aa?aioe-

?iaaoue nio?aiaiea o?aaoaiiai ii?yaeea au/eneaiee. (?anniio?e-

oa iae?in

#DEFINE SQUARE(X) X * X

i?e ia?auaiee e iae, eae SQUARE(Z+1)). Caeanue aicieeatho aeaaea

iaeioi?ua /enoi eaene/aneea i?iaeaiu: iaaeaeo eiaiai iae?i e

eaaie e?oaeie neiaeie, ioe?uaathuae nienie aa a?aoiaioia, ia

aeieaeii auoue ieeaeeo i?iaaeia.

Oai ia iaiaa aiia?ao iae?inia yaeyaony aanueia oeaiiui.

Iaeei i?aeoe/aneee i?eia? aeaao iienuaaaiay a aeaaa 7 noaiaea?-

oiay aeaeeioaea aaiaea-auaiaea, a eioi?ie GETCHAR e PUTCHAR

ii?aaeaeaiu eae iae?inu (i/aaeaeii PUTCHAR aeieaeia eiaoue a?ao-

iaio), /oi iicaieyao ecaaaeaoue cao?ao ia ia?auaiea e ooieoeee

i?e ia?aaioea eaaeaeiai neiaiea.

Ae?oaea aiciiaeiinoe iae?ii?ioeanni?a iienaiu a i?eeiaeaiee

A.

Oi?aaeiaiea 4-9.

Ii?aaeaeeoa iae?in SWAP(X, Y), eioi?ue iaiaieaaao cia/a-

ieyie aeaa naieo a?aoiaioa oeia INT. (A yoii neo/aa iiiiaeao

aei/iay no?oeoo?a).

· 98 –

5.Oeacaoaee e ianneau

Oeacaoaeue – yoi ia?aiaiiay, niaea?aeauay aae?an ae?oaie ia-

?aiaiiie. oeacaoaee i/aiue oe?iei eniieuecothony a ycuea “C”.

Yoi i?ienoiaeeo io/anoe iioiio, /oi eiiaaea iie aeatho aaeeino-

aaiioth aiciiaeiinoue au?aceoue ioaeiia aeaenoaea, a io/anoe iioi-

io, /oi iie iau/ii aaaeoo e aieaa eiiiaeoiui e yooaeoeaiui

i?ia?aiiai, /ai oa, eioi?ua iiaoo auoue iieo/aiu ae?oaeie nii-

niaaie.

Oeacaoaee iau/ii niaoeaatho a iaeio eo/o n iia?aoi?aie

GOTO, oa?aeoa?ecoy eo eae /oaeaniue niinia iaienaiey i?ia-

?aii, eioi?ua iaaiciiaeii iiiyoue. Yoi aaconeiaii ni?Aaaaeeeai,

anee oeacaoaee eniieuecothony aaccaaioii; i/aiue i?inoi aaanoe

oeacaoaee, eioi?ua oeacuaatho ia /oi-oi niaa?oaiii iaiaeeaeai-

iia. Iaeiaei, i?e ii?aaeaeaiiie aeenoeeieeia, eniieueciaaiea oea-

caoaeae iiiiaaao aeinoe/ue yniinoe e i?inoiou. Eiaiii yoio an-

iaeo iu iiiuoaainy caeanue i?ieeethno?e?iaaoue.

5.1. Oeacaoaee e aae?ana

Oae eae oeacaoaeue niaea?aeeo aae?an iauaeoa, yoi aeaao aic-

iiaeiinoue “einaaiiiai” aeinooia e yoiio iauaeoo /a?ac oeaca-

oaeue. I?aaeiieiaeei, /oi o – ia?aiaiiay, iai?eia?, oeia INT, a

?o – oeacaoaeue, nicaeaiiue iaeei aua ia oeacaiiui niiniaii.

Oia?iay iia?aoeey & auaeaao aae?an iauaeoa, oae /oi iia?aoi?

?o = &o;

i?enaaeaaao aae?an o ia?aiaiiie ?o; aiai?yo, /oi ?o “oea-

cuaaao” ia o. Iia?aoeey & i?eiaieia oieueei e ia?aiaiiui e

yeaiaioai ianneaa, eiino?oeoeee aeaea &(o-1) e &3 yaeythony ia-

caeiiiuie. Iaeuecy oaeaea iieo/eoue aae?an ?aaeno?iaie ia?aiai-

iie.

Oia?iay iia?aoeey * ?anniao?eaaao naie iia?aiae eae aae?an

eiia/iie oeaee e ia?auaaony ii yoiio aae?ano, /oiau ecaea/ue

niaea?aeeiia. Neaaeiaaoaeueii, anee Y oiaea eiaao oei INT, oi

Y = *?o;

i?enaaeaaao Y niaea?aeeiia oiai, ia /oi oeacuaaao ?o. Oae iin-

eaaeiaaoaeueiinoue

?o = &o;

Y = *?o;

i?enaaeaaao Y oi aea naiia cia/aiea, /oi e iia?aoi?

Y = X;

Ia?aiaiiua, o/anoaothuea ai anai yoii iaiaoiaeeii iienaoue:

INT X, Y;

INT *PX;

· 99 –

n iienaieai aeey X e Y iu oaea iaiaeiiie?aoii ano?a/aeenue.

Iienaiea oeacaoaey

INT *PX;

yaeyaony iiaui e aeieaeii ?anniao?eaaoueny eae iiaiiie/aneia;

iii aiai?eo, /oi eiiaeiaoeey *PX eiaao oei INT. Yoi icia/aao,

/oi anee PX iiyaeyaony a eiioaenoa *PX, oi yoi yeaeaaeaioii

ia?aiaiiie oeia INT. Oaeoe/anee neioaenen iienaiey ia?aiai-

iie eieoe?oao neioaenen au?aaeaiee, a eioi?uo yoa ia?aiaiiay

iiaeao iiyaeyoueny. Yoi caia/aiea iieacii ai anao neo/ayo,

naycaiiuo ni neiaeiuie iienaieyie. Iai?eia?,

DOUBLE ATOF(), *DP;

aiai?eo, /oi ATOF() e *DP eiatho a au?aaeaieyo cia/aiey oeia

DOUBLE.

Au aeieaeiu oaeaea caiaoeoue, /oi ec yoiai iienaiey neaaeo-

ao, /oi oeacaoaeue iiaeao oeacuaaoue oieueei ia ii?aaeaeaiiue aeae

iauaeoia.

Oeacaoaee iiaoo aoiaeeoue a au?aaeaiey. Iai?eia?, anee PX

oeacuaaao ia oeaeia X, oi *PX iiaeao iiyaeyoueny a ethaii eii-

oaenoa, aaea iiaeao ano?aoeoueny X. Oae iia?aoi?

Y = *PX + 1

i?enaaeaaao Y cia/aiea, ia 1 aieueoaa cia/aiey X;

PRINTF(“%DN”, *PX)

ia/aoaao oaeouaa cia/aiea X;

D = SQRT((DOUBLE) *PX)

iieo/aao a D eaaae?aoiue ei?aiue ec X, i?e/ai aei ia?aaea/e ooi-

eoeee SQRT cia/aiea X i?aia?acoaony e oeio DOUBLE. (Niio?e

aeaao 2).

A au?aaeaieyo aeaea

Y = *PX + 1

oia?iua iia?aoeee * e & naycaiu ni naiei iia?aiaeii aieaa

e?aiei, /ai a?eoiaoe/aneea iia?aoeee, oae /oi oaeia au?aaeaiea

aa?ao oi cia/aiea, ia eioi?ia oeacuaaao PX, i?eaaaeyao 1 e

i?enaaeaaao ?acoeueoao ia?aiaiiie Y. Iu anei?a aa?iainy e oi-

io, /oi iiaeao icia/aoue au?aaeaiea

Y = *(PX + 1)

Nnueee ia oeacaoaee iiaoo iiyaeyoueny e a eaaie /anoe

i?enaaeaaiee. Anee PX oeacuaaao ia X, oi

*PX = 0

· 100 –

iieaaaao X ?aaiui ioeth, a

*PX += 1

oaaee/eaaao aai ia aaeeieoeo, eae e au?aaeaiea

(*PX)++

E?oaeua neiaee a iineaaeiai i?eia?a iaiaoiaeeiu; anee eo iion-

oeoue, oi iineieueeo oia?iua iia?aoeee, iiaeiaiua * e ++, auiie-

iythony ni?aaa iaeaai, yoi au?aaeaiea oaaee/eo PX, a ia oo ia-

?aiaiioth, ia eioi?oth ii oeacuaaao.

E iaeiiaoe, oae eae oeacaoaee yaeythony ia?aiaiiuie, oi n

ieie iiaeii ia?auaoueny, eae e n inoaeueiuie ia?aiaiiuie. Anee

PY – ae?oaie oeacaoaeue ia ia?aiaiioth oeia INT, oi

PY = PX

eiie?oao niaea?aeeiia PX a PY, a ?acoeueoaoa /aai PY oeacuaaao

ia oi aea, /oi e PX.

5.2. Oeacaoaee e a?aoiaiou ooieoeee

Oae eae a “n” ia?aaea/a a?aoiaioia ooieoeeyi inouanoaeyao-

ny “ii cia/aieth”, aucaaiiay i?ioeaaeo?a ia eiaao iaiin?aaeno-

aaiiie aiciiaeiinoe eciaieoue ia?aiaiioth ec aucuaathuae i?ia-

?aiiu. *oi aea aeaeaoue, anee aai aeaenoaeoaeueii iaaei eciaieoue

a?aoiaio? iai?eia?, i?ia?aiia ni?oe?iaee caoioaea au iiia-

iyoue aeaa ia?ooathueo ii?yaeie yeaiaioa n iiiiuueth ooieoeee n

eiaiai SWAP. Aeey yoiai iaaeinoaoi/ii iaienaoue

SWAP(A, B);

ii?aaeaeea ooieoeeth SWAP i?e yoii neaaeothuei ia?acii:

SWAP(X, Y) /* WRONG */

INT X, Y;

INT TEMP;

TEMP = X;

X = Y;

Y = TEMP;

ec-ca auciaa ii cia/aieth SWAP ia iiaeao aicaeaenoaiaaoue ia

aaoiaiou A e B a aucuaathuae ooieoeee.

E n/anoueth, ana aea eiaaony aiciiaeiinoue iieo/eoue aeaeaaiue

yooaeo. Aucuaathuay i?ia?aiia ia?aaeaao oeacaoaee iiaeeaaeaueo

eciaiaieth cia/aiee:

SWAP(&A, &B);

· 101 –

oae eae iia?aoeey & auaeaao aae?an ia?aiaiiie, oi &A yaeyaony

oeacaoaeai ia A. A naiie SWAP a?aoiaiou iienuaathony eae oea-

caoaee e aeinooi e oaeoe/aneei iia?aiaeai inouanoaeyaony /a?ac

ieo.

SWAP(PX, PY) /* INTERCHANGE *PX AND *PY */

INT *PX, *PY;

INT TEMP;

TEMP = *PX;

*PX = *PY;

*PY = TEMP;

Oeacaoaee a ea/anoaa a?aoiaioia iau/ii eniieuecothony a

ooieoeeyo, eioi?ua aeieaeiu aica?auaoue aieaa iaeiiai cia/aiey.

(Iiaeii neacaoue, /oi SWAP aOca?auaao aeaa cia/aiey, iiaua cia-

/aiey aa a?aoiaioia). A ea/anoaa i?eia?a ?anniio?ei ooieoeeth

GETINT, eioi?ay inouanoaeyao i?aia?aciaaiea iinooiathueo a

naiaieiii oi?iaoa aeaiiuo, ?acaeaeyy iioie neiaieia ia oeaeua

cia/aiey, ii iaeiiio oeaeiio ca iaeii ia?auaiea. Ooieoeey GETINT

aeieaeia aica?auaoue eeai iaeaeaiiia cia/aiea, eeai i?eciae eii-

oea oaeea, anee aoiaeiua aeaiiua iieiinoueth en/a?iaiu. Yoe cia-

/aiey aeieaeiu aica?auaoueny eae ioaeaeueiua iauaeou, eaeia au

cia/aiea ie eniieueciaaeinue aeey EOF, aeaaea anee yoi cia/aiea

aaiaeeiiai oeaeiai.

Iaeii ec ?aoaiee, iniiauaathuaany ia iienuaaaiie a aeaaa 7

ooieoeee aaiaea SCANF, ninoieo a oii, /oiau i?e auoiaea ia ei-

iaoe oaeea GETINT aica?auaea EOF a ea/anoaa cia/aiey ooieoeee;

ethaia ae?oaia aica?auaiiia cia/aiea aiai?eo i iaoiaeaeaiee ii?-

iaeueiiai oeaeiai. *eneaiiia aea cia/aiea iaeaeaiiiai oeaeiai

aica?auaaony /a?ac a?aoiaio, eioi?ue aeieaeai auoue oeacaoaeai

oeaeiai. Yoa i?aaiecaoeey ?acaeaeyao noaoon eiioea oaeea e /en-

eaiiua cia/aiey.

Neaaeothuee oeeee caiieiyao iannea oeaeuie n iiiiuueth ia?aua-

iee e ooieoeee GETINT:

INT N, V, ARRAY[SIZE];

FOR (N = 0; N = ‘0’ && C = ALLOCBUF && P = ALLOCBUF && P = e o.ae., ?aaioatho

iaaeeaaeauei ia?acii. Iai?eia?,

P 0 IF S>T */

CHAR S[], T[];

INT I;

I = 0;

WHILE (S[I] == T[I])

IF (S[I++] == ‘0’)

RETURN(0);

RETURN(S[I]-T[I]);

Aio aa?ney STRCMP n oeacaoaeyie:

STRCMP(S, T) /* RETURN 0 IF S>T */ CHAR *S, *T;

FOR ( ; *S == *T; S++, T++)

IF (*S == ‘0’)

RETURN(0);

RETURN(*S-*T);

oae eae ++ e—iiaoo auoue eae iinooeeniuie, oae e

i?aoeeniuie iia?aoeeyie, ano?a/athony ae?oaea eiiaeiaoeee * e

++ e –, oioy e iaiaa /anoi.

Iai?eia?

*++P

· 111 –

oaaee/eaaao P aei ecaea/aiey neiaiea, ia eioi?ue oeacuaaao

P, a

*–P

nia/aea oiaiueoaao P.

Oi?aaeiaiea 5-2.

Iaieoeoa aa?eaio n oeacaoaeyie ooieoeee STRCAT ec aeaau

2: STRCAT(S, T) eiie?oao no?ieo T a eiiaoe S.

Oi?aaeiaiea 5-3.

Iaieoeoa iae?in aeey STRCPY.

Oi?aaeiaiea 5-4.

Ia?aieoeoa iiaeoiaeyuea i?ia?aiiu ec i?aaeuaeoueo aeaa e oi-

?aaeiaiee, eniieuecoy oeacaoaee aianoi eiaeaenaoeee ianneaia.

Oi?ioea aiciiaeiinoe aeey yoiai i?aaeinoaaeytho ooieoeee GETLINE

/aeaau 1 e 4/, ATOI, ITOA e eo aa?eaiou /aeaau 2, 3 e 4/,

REVERSE /aeaaa 3/, INDEX e GETOP /aeaaa 4/.

5.6. Oeacaoaee – ia oeaeua.

Au, aiciiaeii, ia?aoeee aieiaiea a i?aaeuaeoueo “n”-i?ia-

?aiiao ia aeiaieueii iai?eioaeaeaiiia ioiioaiea e eiie?iaaieth

oeacaoaeae. A iauai yoi aa?ii, /oi ia aieueoeinoaa iaoei oea-

caoaeue iiaeii i?enaieoue oeaeiio e ia?aaeaoue aai ia?aoii, ia ec-

iaiea aai; i?e yoii ia i?ienoiaeeo ieeaeiai ianooaae?iaaiey

eee i?aia?aciaaiey e ie iaeei aeo ia oa?yaony. e niaeaeaieth,

yoi aaaeao e aieueiiio ia?auaieth n ooieoeeyie, aica?auathueie

oeacaoaee, eioi?ua caoai i?inoi ia?aaeathony ae?oaei ooieoeeyi,

· iaiaoiaeeiua iienaiey oeacaoaeae /anoi iioneathony. ?anniio-

?ei, iai?eia?, ooieoeeth STRSAVE(S), eioi?ay eiie?oao no?ieo S

a iaeioi?ia ianoi aeey o?aiaiey, auaeaeyaiia iin?aaenoaii ia?a-

uaiey e ooieoeee ALLOC, e aica?auaao oeacaoaeue ia yoi ianoi.

I?aaeeueii iia aeieaeia auoue caienaia oae:

CHAR STRSAVE(S) / SAVE STRING S SOMEWHERE */ CHAR *S;

CHAR *P, *ALLOC();

IF ((P = ALLOC(STRLEN(S)+1)) != NULL)

STRCPY(P, S);

RETURN(P);

ia i?aeoeea nouanoaoao neeueiia no?aieaiea iioneaoue iienaiey:

· 112 –

STRSAVE(S) / SAVE STRING S SOMEWHERE */

CHAR *P;

IF ((P = ALLOC(STRLEN(S)+1)) != NULL)

STRCPY(P, S);

RETURN(P);

Yoa i?ia?aiia aoaeao i?aaeeueii ?aaioaoue ia iiiaeo iaoe-

iao, iioiio /oi ii oiie/aieth ooieoeee e a?aoiaiou eiatho oei

INT, a oeacaoaeue e oeaeia iau/ii iiaeii aaciianii ia?anueaoue

ooaea e ia?aoii. Iaeiaei oaeie noeeue i?ia?aiie?iaaiey a naiai

nouanoaa yaeyaony ?eneiaaiiui, iineieueeo caaeneo io aeaoaeae

?aaeecaoeee e a?oeoaeoo?u iaoeiu e iiaeao i?eaanoe e iai?a-

aeeueiui ?acoeueoaoai ia eiie?aoiii eniieuecoaiii aaie eiiieey-

oi?a. ?acoiiaa anthaeo eniieueciaaoue iieiua iienaiey. (Ioeaaei/-

iay i?ia?aiia LINT i?aaeoi?aaeeo i oaeeo eiino?oeoeeyo, anee

iie ii iainoi?iaeiinoe ana aea iiyayony).

5.7. Iiiaiia?iua ianneau.

A ycuea “C” i?aaeoniio?aiu i?yiioaieueiua iiiaiia?iua ian-

neau, oioy ia i?aeoeea nouanoaoao oaiaeaioeey e eo cia/eoaeueii

aieaa ?aaeeiio eniieueciaaieth ii n?aaiaieth n ianneaaie oeaca-

oaeae. A yoii ?acaeaea iu ?anniio?ei iaeioi?ua eo naienoaa.

?anniio?ei caaea/o i?aia?aciaaiey aeiy ianyoea a aeaiue aiaea

e iaiai?io. Iai?eia?, 1-ia ia?oa yaeyaony 60-i aeiai iaaeni-

einiiai aiaea e 61-i aeiai aenieiniiai aiaea. Aeaaaeoa aaaaeai

aeaa ooieoeee aeey auiieiaiey yoeo i?aia?aciaaiee: DAY_OF_YEAR

i?aia?acoao ianyoe e aeaiue a aeaiue aiaea, a MONTH_DAY i?aia?aco-

ao aeaiue aiaea a ianyoe e aeaiue. Oae eae yoa iineaaeiyy ooieoeey

aica?auaao aeaa cia/aiey, oi a?aoiaiou ianyoea e aeiy aeieaeiu

auoue oeacaoaeyie:

MONTH_DAY(1977, 60, &M, &D)

Iieaaaao M ?aaiui 3 e D ?aaiui 1 (1-ia ia?oa).

Iaa yoe ooieoeee ioaeaeathony a iaeiie e oie aea eioi?iaoeeii-

iie oaaeeoea, oeacuaathuae /enei aeiae a eaaeaeii ianyoea. Oae eae

/enei aeiae a ianyoea a aenieiniii e a iaaenieiniii aiaeo ioee-

/aaony, oi i?iua i?aaenoaaeoue eo a aeaea aeaoo no?ie aeaoia?iiai

ianneaa, /ai iuoaoueny i?ineaaeeaaoue ai a?aiy au/eneaiee, /oi

eiaiii i?ienoiaeeo a oaa?aea. Aio yoio iannea e auiieiythuea

yoe i?aia?aciaaiey ooieoeee:

STATIC INT DAY_TAB[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)

;

· 113 –

DAY_OF_YEAR(YEAR, MONTH, DAY) /* SET DAY OF YEAR */

INT YEAR, MONTH, DAY; /* FROM MONTH & DAY */

INT I, LEAP;

LEAP = YEAR%4 == 0 && YEAR%100 != 0 !! YEAR%400 == 0;

FOR (I = 1; I DAY_TAB[LEAP][I]; I++)

YEARDAY -= DAY_TAB[LEAP][I];

*PMONTH = I;

*PDAY = YEARDAY;

Iannea DAY_TAB aeieaeai auoue aiaoiei eae aeey DAY_OF_YEAR, oae

e aeey MONTH_DAY, iineieueeo ii eniieuecoaony iaaeie yoeie ooi-

eoeeyie.

Iannea DAY_TAB yaeyaony ia?aui aeaoia?iui ianneaii, n ei-

oi?ui iu eiaai aeaei. Ii ii?aaeaeaieth a “C” aeaoia?iue iannea

ii nouanoao yaeyaony iaeiiia?iui ianneaii, eaaeaeue yeaiaio ei-

oi?iai yaeyaony ianneaii. Iiyoiio eiaeaenu caienuaathony eae

DAY_TAB[I][J]

a ia

DAY_TAB [I, J]

eae a aieueoeinoaa ycueia. A inoaeueiii n aeaoia?iuie ianneaaie

iiaeii a iniiaiii ia?auaoueny oaeei aea ia?acii, eae a ae?oaeo

ycueao. Yeaiaiou o?aiyony ii no?ieai, o.a. I?e ia?auaiee e

yeaiaioai a ii?yaeea eo ?aciauaiey a iaiyoe auno?aa anaai ec-

iaiyaony naiue i?aaue eiaeaen.

Iannea eieoeeaeece?oaony n iiiiuueth nienea ia/aeueiuo cia-

/aiee, caeeth/aiiuo a oeao?iua neiaee; eaaeaeay no?iea aeaoia?-

iiai ianneaa eieoeeaeece?oaony niioaaonoaothuei iiaenieneii. Iu

iiianoeee a ia/aei ianneaa DAY_TAB noieaaoe ec ioeae aeey oi-

ai, /oiau iiia?a ianyoeaa eciaiyeenue anoanoaaiiui ia?acii io

1 aei 12, a ia io 0 aei 11. Oae eae ca yeiiiieth iaiyoe o ian iiea ia
iaa?aaeaeatho, oaeie niinia i?iua, /ai iiaeaiiea eiaeae-nia.

Anee aeaoia?iue iannea ia?aaeaaony ooieoeee, oi iienaiea

niioaaonoaothuaai a?aoiaioa ooieoeee aeieaeii niaea?aeaoue eiee/an-

oai noieaoeia; eiee/anoai no?ie ianouanoaaiii, iineieueeo, eae

e i?aaeaea, oaeoe/anee ia?aaeaaony oeacaoaeue. A iaoai eiie?ao-

iii neo/aa yoi oeacaoaeue iauaeoia, yaeythueony ianneaaie ec

· 114 –

13 /enae oeia INT. Oaeei ia?acii, anee au o?aaiaaeinue ia?a-

aeaoue iannea DAY_TAB ooieoeee F, oi iienaiea a F eiaei au aeae:

F(DAY_TAB)

INT DAY_TAB[2][13];

Oae eae eiee/anoai no?ie yaeyaony ianouanoaaiiui, oi iiena-

iea a?aoiaioa a F iiaei au auoue oaeei:

INT DAY_TAB[][13];

eee oaeei

INT (*DAY_TAB)[13];

a eioi?i aiai?eony, /oi a?aoiaio yaeyaony oeacaoaeai ianneaa

ec 13 oeaeuo. E?oaeua neiaee caeanue iaiaoiaeeiu, iioiio /oi

eaaae?aoiua neiaee [] eiatho aieaa aunieee o?iaaiue noa?oeino-

aa, /ai *; eae iu oaeaeei a neaaeothuai ?acaeaea, aac e?oaeuo

neiaie

INT *DAY_TAB[13];

yaeyaony iienaieai ianneaa ec 13 oeacaoaeae ia oeaeua.

5.8. Ianneau oeacaoaeae; oeacaoaee oeacaoaeae

Oae eae oeacaoaee naie yaeythony ia?aiaiiuie, oi au aiie-

ia iiaee au iaeeaeaoue eniieueciaaiey ianneaa oeacaoaeae. Yoi

aeaenoaeoaeueii oae. Iu i?ieeethno?e?oai yoi iaienaieai i?ia-

?aiiu ni?oe?iaee a aeoaaeoiii ii?yaeea iaai?a oaenoiauo

no?ie, i?aaeaeueii oi?iuaiiiai aa?eaioa ooeeeou SORT iia?aoee-

iiiie nenoai UNIX.

A aeaaa 3 iu i?eaaee ooieoeeth ni?oe?iaee ii oaeeo, eioi-

?ay oii?yaei/eaaea iannea oeaeuo. Yoio aea aeai?eoi aoaeao ?aai-

oaoue e caeanue, oioy oaia?ue iu aoaeai eiaoue aeaei ni no?i/eaie

oaenoa ?acee/iie aeeeiu, eioi?ua, a ioee/ea io oeaeuo, iaeuecy

n?aaieaaoue eee ia?aiauaoue n iiiiuueth iaeiie iia?aoeee. Iu ioae-

aeaainy a oaeii i?aaenoaaeaiee aeaiiuo, eioi?ia au iicaieyei

oaeiaii e yooaeoeaii ia?aaaouaaoue no?iee oaenoa ia?aiaiiie

aeeeiu.

Caeanue e aicieeatho ianneau oeacaoaeae. Anee iiaeeaaeauea

ni?oe?iaea n?iee o?aiyony iaeia ca ae?oaie a aeeeiiii neiaieue-

iii ianneaa (oi?aaeyaiii, iai?eia?, ooieoeeae ALLOC), oi e

eaaeaeie no?iea iiaeii ia?aoeoueny n iiiiuueth oeacaoaey ia aa

ia?aue neiaie. Naie oeacaoaee iiaeii o?aieoue a ianneaa. aeaa

no?iee iiaeii n?aaieoue, ia?aaeaa eo oeacaoaee ooieoeee STRCMP.

· 115 –

Anee aeaa ?aniieiaeaiiua a iai?aaeeueiii ii?yaeea no?iee aeieaeiu

auoue ia?anoaaeaiu, oi oaeoe/anee ia?anoaaeythony oeacaoaee a

ianneaa oeacaoaeae, a ia naie oaenou no?ie. Yoei eneeth/athony

n?aco aeaa naycaiiua i?iaeaiu: neiaeiiai oi?aaeaiey iaiyoueth e

aieueoeo aeiiieieoaeueiuo cao?ao ia oaeoe/aneoth ia?anoaiiaeo

no?ie.

I?ioeann ni?oe?iaee aeeth/aao o?e oaaa:

/oaiea anao no?ie aaiaea

eo ni?oe?iaea

auaiae eo a i?aaeeueiii ii?yaeea

Eae iau/ii, eo/oa ?acaeaeeoue i?ia?aiio ia ianeieueei ooieoeee a

niioaaonoaee n anoanoaaiiui aeaeaieai caaea/e e auaeaeeoue aaaeo-

uoth ooieoeeth, oi?aaeythuoth ?aaioie anae i?ia?aiiu.

Aeaaaeoa ioeiaeei ia iaeioi?ia a?aiy ?anniio?aiea oaaa ni?oe-

?iaee e nin?aaeioi/einy ia no?oeoo?a aeaiiuo e aaiaea-auaiaea.

Ooieoeey, inouanoaeythuay aaiae, aeieaeia ecaea/ue neiaieu eaaeaeie

no?iee, caiiiieoue eo e iino?ieoue iannea oeacaoaeae no?ie.

Iia aeieaeia oaeaea iiaen/eoaoue /enei no?ie ai aaiaea, oae eae

yoa eioi?iaoeey iaiaoiaeeia i?e ni?oe?iaea e auaiaea. oae eae

ooieoeey aaiaea a ninoiyiee ni?aaeoueny oieueei n eiia/iui /en-

eii aaiaeeiuo no?ie, a neo/aa neeoeii aieueoiai eo /enea iia

iiaeao aica?auaoue iaeioi?ia /enei, ioee/iia io aiciiaeiiai

/enea no?ie, iai?eia? -1. Ooieoeey inouanoaeythuay auaiae, aeie-

aeia ia/aoaoue no?iee a oii ii?yaeea, a eaeii iie iiyaeythony a

ianneaa oeacaoaeae.

#DEFINE NULL 0

#DEFINE LINES 100 /* MAX LINES TO BE SORTED */

MAIN() /* SORT INPUT LINES */

(

CHAR *LINEPTR[LINES]; /*POINTERS TO TEXT LINES */

INT NLINES; /* NUMBER OF INPUT LINES READ */

IF ((NLINES = READLINES(LINEPTR, LINES)) >= 0) ( SORT(LINEPTR, NLINES);

WRITELINES(LINEPTR, NLINES);

)

ELSE

PRINTF(“INPUT TOO BIG TO SORTN”);

)

#DEFINE MAXLEN 1000

· 116 –

READLINES(LINEPTR, MAXLINES) /* READ INPUT LINES */

CHAR LINEPTR[]; / FOR SORTING */

INT MAXLINES;

(

INT LEN, NLINES;

CHAR *P, *ALLOC(), LINE[MAXLEN];

NLINES = 0;

WHILE ((LEN = GETLINE(LINE, MAXLEN)) > 0)

IF (NLINES >= MAXLINES)

RETURN(-1);

ELSE IF ((P = ALLOC(LEN)) == NULL)

RETURN (-1);

ELSE (

LINE[LEN-1] = ‘0’; /* ZAP NEWLINE */

STRCPY(P,LINE);

LINEPTR[NLINES++] = P;

)

RETURN(NLINES);

)

Neiaie iiaie no?iee a eiioea eaaeaeie no?iee oaeaeyaony, oae /oi

ii ieeae ia aoaeao aeeyoue ia ii?yaeie, a eioi?ii ni?oe?othony

no?iee.

WRITELINES(LINEPTR, NLINES) /* WRITE OUTPUT LINES */

CHAR *LINEPTR[];

INT NLINES;

(

INT I;

FOR (I = 0; I = 0)

PRINTF(“%SN”, *LINEPTR++);

)

caeanue *LINEPTR nia/aea oeacuaaao ia ia?aoth no?ieo; eaaeaeia

oaaee/aiea ia?aaeaeaaao oeacaoaeue ia neaaeothuoth no?ieo, a oi

a?aiy eae NLINES oauaaao aei ioey.

Ni?aaeaoenue n aaiaeii e auaiaeii, iu iiaeai ia?aeoe e ni?-

oe?iaea. i?ia?aiia ni?oe?iaee ii oaeeo ec aeaau 3 o?aaoao

i/aiue iaaieueoeo eciaiaiee: aeieaeiu auoue iiaeeoeoee?iaaiu iiena-

iey, a iia?aoeey n?aaiaiey auaeaeaia a ioaeaeueioth ooieoeeth. In-

iiaiie aeai?eoi inoaaony oai aea naiui, e yoi aeaao iai ii?a-

aeaeaiioth oaa?aiiinoue, /oi ii ii-i?aaeiaio aoaeao ?aaioaoue.

SORT(V, N) /* SORT STRINGS V[0] … V[N-1] */

CHAR V[]; / INTO INCREASING ORDER */

INT N;

(

INT GAP, I, J;

CHAR *TEMP;

FOR (GAP = N/2; GAP > 0; GAP /= 2)

FOR (I = GAP; I = 0; J -= GAP) (

IF (STRCMP(V[J], V[J+GAP]) 12) ? NAME[0] : NAME[N]);

)

· 119 –

Iienaiea ianneaa oeacaoaeae ia neiaieu NAME oi/ii oaeia aea,

eae aiaeiae/iia iienaiea LINEPTR a i?eia?a n ni?oe?iaeie.

Eieoeeaeecaoi?ii yaeyaony i?inoi nienie neiaieueiuo no?ie;

eaaeaeay no?iea i?enaaeaaaony niioaaonoaothuae iiceoeee a ianne-

aa. Aieaa oi/ii, neiaieu I-ie no?iee iiiauathony a eaeia-oi

eiia ianoi, a aa oeacaoaeue o?aieony a NAME[I]. Iineieueeo

?acia? ianneaa NAME ia oeacai, eiiieeyoi? nai iiaen/eouaaao

eiee/anoai eieoeeaeecaoi?ia e niioaaonoaaiii onoaiaaeeaaao

i?aaeeueiia /enei.

5.10. Oeacaoaee e iiiaiia?iua ianneau

Ia/eiathuea eco/aoue ycue “n” eiiaaea noaiiayony a ooiee

ia?aae aii?inii i ?acee/ee iaaeaeo aeaoia?iui ianneaii e ianne-

aii oeacaoaeae, oaeei eae NAME a i?eaaaeaiiii auoa i?eia?a.

Anee eiathony iienaiey

INT A[10][10];

INT *B[10];

oi A e B iiaeii eniieueciaaoue noiaeiui ia?acii a oii niunea,

/oi eae A[5][5], oae e B[5][5] yaeythony caeiiiuie nnueeaie

ia ioaeaeueiia /enei oeia INT. Ii A – ianoiyuee iannea: iiae

iaai ioaiaeeony 100 y/aae iaiyoe e aeey iaoiaeaeaiey ethaiai oea-

caiiiai yeaiaioa i?iaiaeyony iau/iua au/eneaiey n i?yiioaieue-

iuie eiaeaenaie. Aeey B, iaeiaei, iienaiea auaeaeyao oieueei 10

oeacaoaeae; eaaeaeue oeacaoaeue aeieaeai auoue onoaiiaeai oae,

/oiau ii oeacuaae ia iannea oeaeuo. anee i?aaeiieiaeeoue, /oi

eaaeaeue ec ieo oeacuaaao ia iannea ec 10 yeaiaioia, oi oiaaea

aaea-oi aoaeao ioaaaeaii 100 y/aae iaiyoe iethn aua aeanyoue y/aae

aeey oeacaoaeae. Oaeei ia?acii, iannea oeacaoaeae eniieuecoao

ianeieueei aieueoee iauai iaiyoe e iiaeao o?aaiaaoue iaee/ea ya-

iiai oaaa eieoeeaeecaoeee. Ii i?e yoii aicieeatho aeaa i?aeio-

uanoaa: aeinooi e yeaiaioo inouanoaeyaony einaaiii /a?ac oea-

caoaeue, a ia iin?aaenoaii oiiiaeaiey e neiaeaiey, e no?iee ian-

neaa iiaoo eiaoue ?acee/iua aeeeiu. Yoi icia/aao, /oi eaaeaeue

yeaiaio B ia aeieaeai iaycaoaeueii oeacuaaoue ia aaeoi? ec 10

yeaiaioia; iaeioi?ua iiaoo oeacuaaoue ia aaeoi? ec aeaoo yea-

iaioia, ae?oaea – ec aeaaaeoeaoe, a o?aouee iiaoo aiiaua ie ia

/oi ia oeacuaaoue.

Oioy iu aaee yoi ianoaeaeaiea a oa?ieiao oeaeuo, ianiiiai-

ii, /aua anaai ianneau oeacaoaeae eniieuecothony oae, eae iu

i?iaeaiiino?e?iaaee ia ooieoeee MONTH_NAME, – aeey o?aiaiey

neiaieueiuo no?ie ?acee/iie aeeeiu.

Oi?aaeiaiea 5-6.

Ia?aieoeoa ooieoeee DAY_OF_YEAR e MONTH_DAY, eniieuecoy

aianoi eiaeaenaoeee oeacaoaee.

· 120 –

5.11. Eiiaiaeiay no?iea a?aoiaioia

Nenoaiiua n?aaenoaa, ia eioi?ua iie?aaony ?aaeecaoeey ycu-

ea “n”, iicaieytho ia?aaeaaaoue eiiaiaeioth no?ieo a?aoiaioia eee

ia?aiao?ia ia/eiathuae auiieiyoueny i?ia?aiia. Eiaaea ooieoeey

MAIN aucuaaaony e eniieiaieth, iia aucuaaaony n aeaoiy a?ao-

iaioaie. Ia?aue a?aoiaio (oneiaii iacuaaaiue ARGC) oeacuaaao

/enei a?aoiaioia a eiiaiaeiie no?iea, n eioi?uie i?ienoiaeeo

ia?auaiea e i?ia?aiia; aoi?ie a?aoiaio (ARGV) yaeyaony oea-

caoaeai ia iannea neiaieueiuo no?ie, niaea?aeaueo yoe a?aoiai-

ou, ii iaeiiio a no?iea. ?aaioa n oaeeie no?ieaie – yoi iau/-

iia eniieueciaaiea iiiaio?iaiaauo oeacaoaeae.

Naioth i?inooth eeethno?aoeeth yoie aiciiaeiinoe e iaiaoiaeeiuo

i?e yoii iienaiee aeaao i?ia?aiia ECHO, eioi?ay i?inoi ia/a-

oaao a iaeio no?ieo a?aoiaiou eiiaiaeiie no?iee, ?acaeaeyy eo

i?iaaeaie. Oaeei ia?acii, anee aeaia eiiaiaea

ECHO HELLO, WORLD

oi auoiaeii aoaeao

HELLO, WORLD

ii niaeaoaieth ARGV[0] yaeyaony eiaiai, ii eioi?iio aucuaaao-

ny i?ia?aiia, oae /oi ARGC ii iaiueoae ia?a ?aaai 1. A i?eaa-

aeaiiii auoa i?eia?a ARGC ?aaai 3, a ARGV[0], ARGV[1] e

ARGV[2] ?aaiu niioaaonoaaiii “ECHO”, “HELLO,” e “WORLD”.

Ia?aui oaeoe/aneei aaoiaioii yaeyaony ARGV[1], a iineaaeiei –

ARGV[ARGC-1]. Anee ARGC ?aaai 1, oi ca eiaiai i?ia?aiiu ia

neaaeoao ieeaeie eiiaiaeiie no?iee a?aoiaioia. Ana yoi iieaca-

ii a ECHO:

MAIN(ARGC, ARGV) /* ECHO ARGUMENTS; 1ST VERSION */

INT ARGC;

CHAR *ARGV[];

(

INT I;

FOR (I = 1; I 0)

PRINTF(“%S%C”,*++ARGV, (ARGC > 1) ? ‘ ‘ : ‘N’);

)

· 121 –

Oae eae ARGV yaeyaony oeacaoaeai ia ia/aei ianneaa no?ie-a?-

aoiaioia, oi, oaaee/ea aai ia 1 (++ARGV), iu auioaeaeaai aai

oeacuaaoue ia iiaeeeiiue a?aoiaio ARGV[1], a ia ia ARGV[0].

Eaaeaeia iineaaeothuaa oaaee/aiea ia?aaeaeaaao aai ia neaaeothuee

a?aoiaio; i?e yoii *ARGV noaiiaeony oeacaoaeai ia yoio a?ao-

iaio. iaeiia?aiaiii aaee/eia ARGC oiaiueoaaony; eiaaea iia ia-

?aoeony a ioeue, ana a?aoiaiou aoaeoo oaea iaia/aoaiu.

Ae?oaie aa?eaio:

MAIN(ARGC, ARGV) /* ECHO ARGUMENTS; 3RD VERSION */ INT ARGC;

CHAR *ARGV[];

(

WHILE (–ARGC > 0)

PRINTF((ARGC > 1) ? “%S” : “%SN”, *++ARGV);

)

Yoa aa?ney iieacuaaao, /oi a?aoiaio oi?iaoa ooieoeee PRINTF

iiaeao auoue au?aaeaieai, oi/ii oae aea, eae e ethaie ae?oaie. Oa-

eia eniieueciaaiea ano?a/aaony ia i/aiue /anoi, ii aai ana aea

noieo caiiiieoue.

Eae aoi?ie i?eia?, aeaaaeoa aianai iaeioi?ua oniaa?oaino-

aiaaiey a i?ia?aiio iouneaiey caaeaiiie eiiaeiaoeee neiaieia

ec aeaau 4. Anee au iiiieoa, iu iiianoeee eneiioth eiiaeiaoeeth

aeoaiei aioo?ue i?ia?aiiu, /oi i/aaeaeii yaeyaony niaa?oaiii

iaoaeiaeaoai?eoaeueiui. Neaaeoy ooeeeoa GREP nenoaiu UNIX, aea-

aaeoa eciaiei i?ia?aiio oae, /oiau yoa eiiaeiaoeey oeacuaa-

eanue a ea/anoaa ia?aiai a?aoiaioa no?iee.

#DEFINE MAXLINE 1000

MAIN(ARGC, ARGV) /* FIND PATTERN FROM FIRST ARGUMENT */ INT ARGC;

CHAR *ARGV[];

(

CHAR LINE[MAXLINE];

IF (ARGC != 2)

PRINTF (“USAGE: FIND PATTERNN”);

ELSE

WHILE (GETLINE(LINE, MAXLINE) > 0)

IF (INDEX(LINE, ARGV[1] >= 0)

PRINTF(“%S”, LINE);

)

Oaia?ue iiaeao auoue ?acaeoa iniiaiay iiaeaeue, eeethno?e?oth-

uay aeaeueiaeoaa eniieueciaaiea oeacaoaeae. I?aaeiieiaeei, /oi

iai iaaei i?aaeoniio?aoue aeaa iaiaycaoaeueiuo a?aoiaioa. Iaeei

ooaa?aeaeaao: “iaia/aoaoue ana no?iee ca eneeth/aieai oao, eioi-

?ua niaea?aeao aeaiioth eiiaeiaoeeth”, aoi?ie aeaneo: “ia?aae eaae-

aeie auaiaeeiie no?ieie aeieaeai ia/aoaoueny aa iiia?”.

· 122 –

Iauai?eiyoui niaeaoaieai a “n”-i?ia?aiiao yaeyaony oi,

/oi a?aoiaio, ia/eiathueeny ni ciaea ieion, aaiaeeo iaiayca-

oaeueiue i?eciae eee ia?aiao?. Anee iu, aeey oiai, /oiau niia-

ueoue ia eiaa?nee, auaa?ai -X, a aeey oeacaiey i ioia?aoeee

ioaeiuo no?ie auaa?ai -N(“iiia?”), oi eiiaiaea

FIND -X -N THE

i?e aoiaeiuo aeaiiuo

NOW IS THE TIME

FOR ALL GOOD MEN

TO COME TO THE AID

OF THEIR PARTY.

Aeieaeia auaeaoue

2:FOR ALL GOOD MEN

Ioaeii, /oiau iaiaycaoaeueiua a?aoiaiou iiaee ?aniieaaaoue-

ny a i?iecaieueiii ii?yaeea, e /oiau inoaeueiay /anoue i?ia?aiiu

ia caaenaea io eiee/anoaa oaeoe/anee i?enoonoaothueo a?aoiai-

oia. a /anoiinoe, aucia ooieoeee INDEX ia aeieaeai niaea?aeaoue

nnueeo ia ARGV[2], eiaaea i?enoonoaoao iaeei iaiaycaoaeueiue

a?aoiaio, e ia ARGV[1], eiaaea aai iao. Aieaa oiai, aeey iieue-

ciaaoaeae oaeiaii, /oiau iaiaycaoaeueiua a?aoiaiou iiaeii auei

iauaaeeieoue a aeaea:

FIND -NX THE

aio naia i?ia?aiia:

#DEFINE MAXLINE 1000

MAIN(ARGC, ARGV) /* FIND PATTERN FROM FIRST ARGUMENT */ INT ARGC;

CHAR *ARGV[];

(

CHAR LINE[MAXLINE], *S;

LONG LINENO = 0;

INT EXCEPT = 0, NUMBER = 0;

WHILE (–ARGC > 0 && (*++ARGV)[0] == ‘-‘)

FOR (S = ARGV[0]+1; *S != ‘0’; S++)

SWITCH (*S) (

CASE ‘X’:

EXCEPT = 1;

BREAK;

· 123 –

CASE ‘N’:

NUMBER = 1;

BREAK;

DEFAULT:

PRINTF(“FIND: ILLEGAL OPTION %CN”, *S);

ARGC = 0;

BREAK;

)

IF (ARGC != 1)

PRINTF(“USAGE: FIND -X -N PATTERNN”);

ELSE

WHILE (GETLINa(LINE, MAXLINE) > 0) (

LINENO++;

IF ((INDEX(LINE, *ARGV) >= 0) != EXCEPT)

IF (NUMBER)

PRINTF(“%LD: “, LINENO);

PRINTF(“%S”, LINE);

)

)

)

A?aoiaio ARGV oaaee/eaaaony ia?aae eaaeaeui iaiaycaoaeueiui

a?aoiaioii, a oi a?aiy eae a?aoiaio ARGC oiaiueoaaony. anee

iao ioeaie, oi a eiioea oeeeea aaee/eia ARGC aeieaeia ?aaiyoueny

1, a *ARGV aeieaeii oeacuaaoue ia caaeaiioth eiiaeiaoeeth. Ia?aoeoa

aieiaiea ia oi, /oi *++ARGV yaeyaony oeacaoaeai a?aoiaioiie

no?iee; (*++ARGV)[0] – aa ia?aue neiaie. E?oaeua neiaee

caeanue iaiaoiaeeiu, iioiio /oi aac ieo au?aaeaiea au i?eiyei

niaa?oaiii ioee/iue (e iai?aaeeueiue) aeae *++(ARGV[0]). Ae?o-

aie i?aaeeueiie oi?iie auea au **++ARGV.

Oi?aaeiaiea 5-7.

Iaieoeoa i?ia?aiio ADD, au/eneythuoth ia?aoiia iieueneia

au?aaeaiea ec eiiaiaeiie no?iee. Iai?eia?,

ADD 2 3 4 + *

au/eneyao 2*(3+4).

Oi?aaeiaiea 5-8.

Iiaeeoeoee?oeoa i?ia?aiiu ENTAB e DETAB (oeacaiiua a ea-

/anoaa oi?aaeiaiee a aeaaa 1) oae, /oiau iie iieo/aee nienie

oaaoeyoeeiiiuo inoaiiaie a ea/anoaa a?aoiaioia. Anee a?aoiai-

ou ionoonoaotho, eniieuecoeoa noaiaea?oioth onoaiiaeo oaaoeyoeee.

Oi?aaeiaiea 5-9.

?anoe?ueoa ENTAB e DETAB oaeei ia?acii, /oiau iie aini?e-

ieiaee nie?auaiioth iioaoeeth

ENTAB M +N

· 124 –

icia/athuoth oaaoeyoeeiiiua inoaiiaee /a?ac eaaeaeua N noieaoeia,

ia/eiay ni noieaoea M. Auaa?eoa oaeiaiia (aeey iieueciaaoaey)

iiaaaeaiea ooieoeee ii oiie/aieth.

Oi?aaeiaiea 5-10.

Iaieoeoa i?ia?aiio aeey ooieoeee TAIL, ia/aoathuae iineaae-

iea N no?ie ec naiaai oaeea aaiaea. Ionoue ii oiie/aieth N ?aa-

ii 10, ii yoi /enei iiaeao auoue eciaiaii n iiiiuueth iaiayca-

oaeueiiai a?aoiaioa, oae /oi

TAIL -N

ia/aoaao iineaaeiea N no?ie. i?ia?aiia aeieaeia aeaenoaiaaoue ?a-

oeeiiaeueii, eaeeie au ia?acoiiuie ie auee au aaiae eee cia/a-

iea N. Ninoaaueoa i?ia?aiio oae, /oiau iia iioeiaeueiui ia?a-

cii eniieueciaaea aeinooiioth iaiyoue: no?iee aeieaeiu o?aieoueny,

eae a ooieoeee SORT, a ia a aeaoia?iii ianneaa oeene?iaaiiiai

?acia?a.

5.12. Oeacaoaee ia ooieoeee

A ycuea “n” naie ooieoeee ia yaeythony ia?aiaiiuie, ii

eiaaony aiciiaeiinoue ii?aaeaeeoue oeacaoaeue ia ooieoeeth, eioi?ue

iiaeii ia?aaaouaaoue, ia?aaeaaaoue ae?oaei ooieoeeyi, iiiauaoue a

ianneau e o.ae. Iu i?ieeethno?e?oai yoi, i?iaaaey iiaeeoeeaoeeth

iaienaiiie ?aiaa i?ia?aiiu ni?oe?iaee oae, /oiau i?e caaeaiee

iaiaycaoaeueiiai a?aoiaioa -N iia au ni?oe?iaaea no?iee aaiaea

/eneaiii, a ia eaeneeia?aoe/anee.

Ni?oe?iaea /anoi ninoieo ec o?ao /anoae – n?aaiaiey, ei-

oi?ia ii?aaeaeyao oii?yaei/eaaiea ethaie ia?u iauaeoia, ia?an-

oaiiaee, eciaiythuae eo ii?yaeie, e aeai?eoia ni?oe?iaee, ino-

uanoaeythuaai n?aaiaiey e ia?anoaiiaee aei oao ii?, iiea

iauaeou ia ?aniieiaeaony a ioaeiii ii?yaeea. Aeai?eoi ni?oe?ia-

ee ia caaeneo io iia?aoeee n?aaiaiey e ia?anoaiiaee, oae /oi,

ia?aaeaaay a iaai ?acee/iua ooieoeee n?aaiaiey e ia?anoaiiaee,

iu iiaeai i?aaieciaaoue ni?oe?iaeo ii ?acee/iui e?eoa?eyi.

Eiaiii oaeie iiaeoiae eniieuecoaony a iaoae iiaie i?ia?aiia

ni?oe?iaee.

Eae e i?aaeaea, eaeneeia?aoe/aneia n?aaiaiea aeaoo no?ie

inouanoaeyaony ooieoeeae STRCMP, a ia?anoaiiaea ooieoeeae

SWAP; iai ioaeia aua ooieoeey NUMCMP, n?aaieaathuay aeaa no?iee

ia iniiaa /eneaiiiai cia/aiey e aica?auathuay oneiaiia oeaca-

iea oiai aea aeaea, /oi e STRCMP. Yoe o?e ooieoeee iienuaathony

a MAIN e oeacaoaee ia ieo ia?aaeathony a SORT. A naith i/a?aaeue

ooieoeey SORT ia?auaaony e yoei ooieoeeyi /a?ac eo oeacaoaee.

iu o?acaee ia?aaioeo ioeaie a a?aoiaioao n oai, /oiau nin?a-

aeioi/eoueny ia aeaaiuo aii?inao.

· 125 –

#DEFINE LINES 100 /* MAX NUMBER OF LINES

TO BE SORTED */

MAIN(ARGC, ARGV) /* SORT INPUT LINES */ INT ARGC;

CHAR *ARGV[];

(

CHAR LINEPTR[LINES]; / POINTERS TO TEXT LINES */

INT NLINES; /* NUMBER OF INPUT LINES READ */

INT STRCMP(), NUMCMP(); /* COMPARSION FUNCTIONS */

INT SWAP(); /* EXCHANGE FUNCTION */

INT NUMERIC = 0; /* 1 IF NUMERIC SORT */

IF(ARGC>1 && ARGV[1][0] == ‘-‘ && ARGV[1][1]==’N’)

NUMERIC = 1;

IF(NLINES = READLINES(LINEPTR, LINES)) >= 0) (

IF (NUMERIC)

SORT(LINEPTR, NLINES, NUMCMP, SWAP);

ELSE

SORT(LINEPTR, NLINES, STRCMP, SWAP);

WRITELINES(LINEPTR, NLINES);

) ELSE

PRINTF(“INPUT TOO BIG TO SORTN”);

)

Caeanue STRCMP, NIMCMP e SWAP – aae?ana ooieoeee; oae eae ecaan-

oii, /oi yoi ooieoeee, iia?aoeey & caeanue ia ioaeia niaa?oaiii

aiaeiae/ii oiio, eae iia ia ioaeia e ia?aae eiaiai ianneaa.

Ia?aaea/a aae?ania ooieoeee i?aaiecoaony eiiieeyoi?ii.

Aoi?ie oaa ninoieo a iiaeeoeeaoeee SORT:

SORT(V, N, COMP, EXCH) /* SORT STRINGS V[0] … V[N-1] */ CHAR V[];
/ INTO INCREASING ORDER */ INT N;

INT (*COMP)(), (*EXCH)();

(

INT GAP, I, J;

FOR(GAP = N/2; GAP > 0; GAP /= 2)

FOR(I = GAP; I = 0; J -= GAP) (

IF((*COMP)(V[J], V[J+GAP]) V2)

RETURN(1);

ELSE

RETURN (0);

)

Caeeth/eoaeueiue oaa ninoieo a aeiaaaeaiee ooieoeee SWAP,

ia?anoaaeythuae aeaa oeacaoaey. Yoi eaaei naeaeaoue, iaiin?aaeno-

aaiii eniieuecoy oi, /oi iu eceiaeeee ?aiaa a yoie aeaaa.

· 127 –

SWAP(PX, PY) /* INTERCHANGE *PX AND *PY */

CHAR *PX[], *PY[];

(

CHAR *TEMP;

TEMP = *PX;

*PX = *PY;

*PY = TEMP;

)

Eiaaony iiiaeanoai ae?oaeo iaiaycyoaeueiuo a?aoiaioia, ei-

oi?ua iiaoo auoue aeeth/aiu a i?ia?aiio ni?oe?iaee: iaeioi?ua

ec ieo ninoaaeytho eioa?aniua oi?aaeiaiey.

Oi?aaeiaiea 5-11.

Iiaeeoeoee?oeoa SORT oaeei ia?acii, /oiau iia ?aaioaea n

iaoeie -R, oeacuaathuae ia ni?oe?iaeo a ia?aoiii (oauaathuai)

ii?yaeea. Eiia/ii, -R aeieaeia ?aaioaoue n -N.

Oi?aaeiaiea 5-12.

Aeiaaaueoa iaiaycaoaeueiue a?aoiaio -F, iauaaeeiythuee aianoa

i?iieniua e no?i/iua aoeau, oae /oiau ?acee/ea ?aaeno?ia ia

o/eouaaeinue ai a?aiy ni?oe?iaee: aeaiiua ec aa?oiaai e ieaeia-

ai ?aaeno?ia ni?oe?othony aianoa, oae /oi aoeaa ‘a’ i?iieniia

e ‘a’ no?i/iia ieacuaathony ninaaeieie , a ia ?acaeaeaiiuie oea-

eui aeoaaeoii.

Oi?aaeiaiea 5-13.

Aeiaaaueoa iaiaycaoaeueiue a?aoiaio -D (“neiaa?iia oii?yaei-

/eaaiea”), i?e iaee/ee eioi?iai n?aaieaathony oieueei aoeau,

/enea e i?iaaeu. Iicaaioueoanue i oii, /oiau yoa ooieoeey ?aai-

oaea e aianoa n -F.

Oi?aaeiaiea 5-14.

Aeiaaaueoa aiciiaeiinoue ia?aaioee iieae, oae /oiau iiaeii

auei ni?oe?iaaoue iiey aioo?e no?ie. Eaaeaeia iiea aeieaeii ni?-

oe?iaaoueny a niioaaonoaee n iacaaeneiui iaai?ii iaiaycaoaeue-

iuo a?aoiaioia. (i?aaeiaoiue oeacaoaeue yoie eieae ni?oe?iaae-

ny n iiiiuueth a?aoiaioia -DF aeey eaoaai?ee oeacaoaey e n -N

aeey iiia?ia no?aieoe).

· 128 –

6. No?oeoo?u.

No?oeoo?a – yoi iaai? ec iaeiie eee aieaa ia?aiaiiuo,

aiciiaeii ?acee/iuo oeiia, na?oiie?iaaiiuo iiae iaeiei eiaiai

aeey oaeianoaa ia?aaioee. (A iaeioi?uo ycueao, naiue ecaanoiue

ec eioi?uo ianeaeue, no?oeoo?u iacuaathony “caienyie”).

O?aaeeoeeiiiui i?eia?ii no?oeoo?u yaeyaony o/aoiay ea?oi/-

ea ?aaioathuaai: “neoaeauee” iienuaaaony iaai?ii ao?eaooia oa-

eeo, eae oaieeey, eiy, io/anoai (o.e.i.), aae?an, eiae nioee-

aeueiiai iaania/aiey, ca?ieaoa e o.ae. Iaeioi?ua ec yoeo ao?e-

aooia naie iiaoo ieacaoueny no?oeoo?aie: o.e.i. Eiaao ian-

eieueei eiiiiiaio, eae e aae?an, e aeaaea ca?ieaoa.

No?oeoo?u ieacuaathony iieaciuie i?e i?aaiecaoeee neiaeiuo

aeaiiuo iniaaiii a aieueoeo i?ia?aiiao, iineieueeo ai iiiaeo

neooaoeeyo iie iicaieytho na?oiie?iaaoue naycaiiua aeaiiua oaeei

ia?acii, /oi n ieie iiaeii ia?auaoueny, eae n iaeiei oeaeui, a

ia eae n ioaeaeueiuie iauaeoaie. A yoie aeaaa iu iinoa?aainy

i?iaeaiiino?e?iaaoue oi, eae eniieuecothony no?oeoo?u. I?ia?ai-

iu, eioi?ua iu aeey yoiai aoaeai eniieueciaaoue, aieueoa, /ai

iiiaea ae?oaea a yoie eieaa, ii ana aea aeinoaoi/ii oia?aiiuo

?acia?ia.

6.1. Iniiaiua naaaeaiey.

Aeaaaeoa niiaa ia?aoeiny e i?ioeaaeo?ai i?aia?aciaaiey aeaou

ec aeaau 5. Aeaoa ninoieo ec ianeieueeeo /anoae oaeeo, eae

aeaiue, ianyoe, e aiae, e, aiciiaeii, aeaiue aiaea e eiy ianyoea. Yoe

iyoue ia?aiaiiuo iiaeii iauaaeaieoue a iaeio no?oeoo?o aeaea:

STRUCT DATE (

INT DAY;

INT MONTH;

INT YEAR;

INT YEARDAY;

CHAR MON_NAME[4];

);

Iienaiea no?oeoo?u, ninoiyuaa ec caeeth/aiiiai a oeao?iua

neiaee nienea iienaiee, ia/eiaaony n eeth/aaiai neiaa STRUCT.

Ca neiaii STRUCT iiaeao neaaeiaaoue iaiaycaoaeueiia eiy, iacuaa-

aiia y?eueii no?oeoo?u (caeanue yoi DATa). Oaeie y?eue eiaioao

no?oeoo?u yoiai aeaea e iiaeao eniieueciaaoueny a aeaeueiaeoai eae

nie?auaiiay caienue iiae?iaiiai iienaiey.

Yeaiaiou eee ia?aiaiiua, oiiiyiooua a no?oeoo?a, iacuaa-

thony /eaiaie. ss?euee e /eaiu no?oeoo? iiaoo eiaoue oaeea aea

eiaia, /oi e iau/iua ia?aiaiiua (o.a. Ia yaeythueany /eaiaie

no?oeoo?), iineieueeo eo eiaia anaaaea iiaeii ?acee/eoue ii eii-

oaenoo. Eiia/ii, iau/ii iaeeiaeiaua eiaia i?enaaeaatho oieueei

oanii naycaiiui iauaeoai.

· 129 –

Oi/ii oae aea, eae a neo/aa ethaiai ae?oaiai aaceniiai oe-

ia, ca i?aaie oeao?iie neiaeie, cae?uaathuae nienie /eaiia,

iiaeao neaaeiaaoue nienie ia?aiaiiuo.

Iia?aoi?

STRUCT ( …) X,Y,Z;

neioaene/anee aiaeiae/ai

INT X,Y,Z;

a oii niunea, /oi eaaeaeue ec iia?aoi?ia iienuaaao X , Y e Z a

ea/anoaa ia?aiaiiuo niioaanoaothueo oeiia e i?eaiaeeo e auaea-

eaieth aeey ieo iaiyoe.

Iienaiea no?oeoo?u, ca eioi?ui ia neaaeoao nienea ia?a-

iaiiuo, ia i?eaiaeeo e auaeaeaieth eaeie-eeai iaiyoe; iii oieue-

ei ii?aaeaeyao oaaeii eee oi?io no?oeoo?u. Iaeiaei, anee oaeia

iienaiea niaaaeaii y?eueii, oi yoio y?eue iiaeao auoue eniieue-

ciaai iicaeiaa i?e ii?aaeaeaiee oaeoe/aneeo yecaiiey?ia no?oe-

oo?. Iai?eia?, anee aeaii i?eaaaeaiiia auoa iienaiea DATE, oi

STRUCT DATE D;

ii?aaeaeyao ia?aiaiioth D a ea/anoaa no?oeoo?u oeia DATE.

Aiaoithth eee noaoe/aneoth no?oeoo?o iiaeii eieoeeaeece?iaaoue,

iiianoea aneaae ca aa ii?aaeaeaieai nienie eieoeeaeecaoi?ia aeey

aa eiiiiiaio:

STRUCT DATE D=( 4, 7, 1776, 186, “JUL”);

*eai ii?aaeaeaiiie no?oeoo?u iiaeao auoue oeacai a au?aaea-

iee n iiiiuueth eiino?oeoeee aeaea

eiy no?oeoo?u . *eai

Iia?aoeey oeacaiey /eaia no?oeoo?u “.” naycuaaao eiy no?oeoo-

?u e eiy /eaia. A ea/anoaa i?eia?a ii?aaeaeei LEAP (i?eciae

aenieiniinoe aiaea) ia iniiaa aeaou, iaoiaeyuaeny a no?oeoo?a

D,

LEAP = D.YEAR % 4 == 0 && D.YEAR % 100 != 0

!! D.YEAR % 400 == 0;

eee i?iaa?ei eiy ianyoea

IF (STRCMP(D.MON_NAME, “AUG”) == 0) …

Eee i?aia?acoai ia?aue neiaie eiaie ianyoea oae, /oiau iii

ia/eiaeinue ni no?i/iie aoeau

D.MON_NAME[0] = LOWER(D.MON_NAME[0]);

· 130 –

No?oeoo?u iiaoo auoue aeiaeaiiuie; o/aoiay ea?oi/ea neoaea-

uaai iiaeao oaeoe/anee auaeyaeaoue oae:

STRUCT PERSON (

CHAR NAME[NAMESIZE];

CHAR ADDRESS[ADRSIZE];

LONG ZIPCODE; /* ii/oiaue eiaeaen */

LONG SS_NUMBER; /* eiae nioe. Iaania/aiey */

DOUBLE SALARY; /* ca?ieaoa */

STRUCT DATE BIRTHDATE; /* aeaoa ?iaeaeaiey */

STRUCT DATE HIREDATE; /* aeaoa iinooieaiey

ia ?aaioo */

);

No?oeoo?a PERSON niaea?aeeo aeaa no?oeoo?u oeia DATE . Anee iu

ii?aaeaeei EMP eae

STRUCT PERSON EMP;

oi

EMP.BIRTHDATE.MONTH

aoaeao nnueaoueny ia ianyoe ?iaeaeaiey. Iia?aoeey oeacaiey /eaia

no?oeoo?u “.” annioeee?oaony neaaa iai?aai.

6.2. No?oeoo?u e ooieoeee.

A ycuea “C” nouanoaoao ?yae ia?aie/aiee ia eniieueciaaiea

no?oeoo?. Iaycaoaeueiua i?aaeea caeeth/athony a oii, /oi aaeein-

oaaiiua iia?aoeee, eioi?ua au iiaeaoa i?iaiaeeoue ni no?oeoo?a-

ie, ninoiyo a ii?aaeaeaiee aa aae?ana n iiiiuueth iia?aoeee & e

aeinooia e iaeiiio ec aa /eaiia. Yoi aea/ao ca niaie oi, /oi

no?oeoo?u iaeuecy i?enaaeaaoue eee eiie?iaaoue eae oeaeia, e /oi

iie ia iiaoo auoue ia?aaeaiu ooieoeeyi eee aica?auaiu eie. (A

iineaaeothueo aa?neyo yoe ia?aie/aiey aoaeoo niyou). Ia oeaca-

oaee no?oeoo? yoe ia?aie/aiey iaeiaei ia iaeeaaeuaathony, oae

/oi no?oeoo?u e ooieoeee ana aea iiaoo n oaeianoaii ?aaioaoue

niaianoii. E iaeiiaoe, aaoiiaoe/aneea no?oeoo?u, eae e aaoi-

iaoe/aneea ianneau, ia iiaoo auoue eieoeeaeece?iaaiu; eieoeea-

eecaoeey aiciiaeia oieueei a neo/aa aiaoieo eee noaoe/aneeo

no?oeoo?.

Aeaaaeoa ?acaa?ai iaeioi?ua ec yoeo aii?inia, ia?aienaa n

yoie oeaeueth ooieoeee ia?ia?aciaaiey aeaou ec i?aaeuaeouae aeaau

oae, /oiau iie eniieueciaaee no?oeoo?u. Oae eae i?aaeea cai-

?auatho iaiin?aaenoaaiioth ia?aaea/o no?oeoo?u ooieoeee, oi iu

aeieaeiu eeai ia?aaeaaaoue ioaeaeueii eiiiiiaiou, eeai ia?aaeaoue

oeacaoaeue anae no?oeoo?u. Ia?aay aiciiaeiinoue aeaiiino?e?oaony

ia i?eia?a ooieoeee DAY_OF_YEAR, eae iu aa iaienaee a aeaaa

5:

D.YEARDAY = DAY_OF_YEAR(D.YEAR, D.MONTH, D.DAY);

· 131 –

ae?oaie niinia ninoieo a ia?aaea/a oeacaoaey. anee iu iieoai

HIREDATE eae

STRUCT DATE HIREDATE;

e ia?aieoai DAY_OF_YEAR ioaeiui ia?acii, iu niiaeai oiaaea ia-

ienaoue

HIREDATE YEARDAY = DAY_OF_YEAR(&HIREDATE);

ia?aaeaaay oeacaoaeue ia HIREDATE ooieoeee DAY_OF_YEAR . Ooie-oeey
aeieaeia auoue iiaeeoeoee?iaaia, iioiio /oi aa a?aoiaio oa-ia?ue
yaeyaony oeacaoaeai, a ia nieneii ia?aiaiiuo.

DAY_OF_YEAR(PD) /* SET DAY OF YEAR FROM MONTH, DAY */ STRUCT DATE *PD;

(

INT I, DAY, LEAP;

DAY = PD->DAY;

LEAP = PD->YEAR % 4 == 0 && PD->YEAR % 100 != 0

!! PD->YEAR % 400 == 0;

FOR (I =1; I MONTH; I++)

DAY += DAY_TAB[LEAP][I];

RETURN(DAY);

)

Iienaiea

STRUCT DATE *PD;

aiai?eo, /oi PD yaeyaony oeacaoaeai no?oeoo?u oeia DATE.

Caienue, iieacaiiay ia i?eia?a

PD->YEAR

yaeyaony iiaie. Anee P – oeacaoaeue ia no?oeoo?o, oi

P-> /eai no?oeoo?u

ia?auaaony e eiie?aoiiio /eaio. (Iia?aoeey -> – yoi ciae ie-

ion, ca eioi?ui neaaeoao ciae “>”.)

Oae eae PD oeacuaaao ia no?oeoo?o, oi e /eaio YEAR iiaeii

ia?aoeoueny e neaaeothuei ia?acii

(*PD).YEAR

ii oeacaoaee no?oeoo? eniieuecothony ianoieueei /anoi, /oi ca-

ienue -> ieacuaaaony oaeiaiui nie?auaieai. E?oaeua neiaee a

(*PD).YEAR iaiaoiaeeiu, iioiio /oi iia?aoeey oeacaiey /eaia

· 132 –

nooeoo?u noa?oa , /ai * . Iaa iia?aoeee, “->” e “.”, annioeee-

?othony neaaa iai?aai, oae /oi eiino?oeoeee neaaa e ni?aaa

ceaeaaeaioiu

P->Q->MEMB (P->Q)->MEMB

EMP.BIRTHDATE.MONTH (EMP.BIRTHDATE).MONTH

Aeey iieiiou ieaea i?eaiaeeony ae?oaay ooieoeey, MONTH_DAY, ia?a-

ienaiiay n eniieueciaaieai no?oeoo?.

MONTH_DAY(PD) /* SET MONTH AND DAY FROM DAY OF YEAR */ STRUCT DATE *PD;

(

INT I, LEAP;

LEAP = PD->YEAR % 4 == 0 && PD->YEAR % 100 != 0

!! PD->YEAR % 400 == 0;

PD->DAY = PD->YEARDAY;

FOR (I = 1; PD->DAY > DAY_TAB[LEAP][I]; I++)

PD->DAY -= DAY_TAB[LEAP][I];

PD->MONTH = I;

)

Iia?aoeee ?aaiou ni no?oeoo?aie “->” e “.” ia?yaeo ni ()

aeey nienea a?aoiaioia e [] aeey eiaeaenia iaoiaeyony ia naiii

aa?oo ea?a?oee no?aoeinoaa iia?aoeee e, neaaeiaaoaeueii, naycu-

aathony i/aiue e?aiei. Anee, iai?eia?, eiaaony iienaiea

STRUCT (

INT X;

INT *Y;

) *P;

oi au?aaeaiea

++P->X

oaaee/eaaao o, a ia ?, oae eae iii yeaeaaeaioii au?aaeaieth

++(P->o). Aeey eciaiaiey ii?yaeea auiieiaiey iia?aoeee iiaeii

eniieueciaaoue e?oaeua neiaee: (++P)->o oaaee/eaaao P aei aein-

ooia e o, a (P++)->X oaaee/eaaao P iinea. (e?oaeua neiaee a

iineaaeiai neo/aa iaiaycaoaeueiu. Ii/aio ?)

Niaa?oaiii aiaeiae/ii *P->Y ecaeaeaao oi, ia /oi oeacu-

aaao Y; *P->Y++ oaaee/eaaao Y iinea ia?aaioee oiai, ia /oi

ii oeacuaaao (oi/ii oae aea, eae e *S++); (*P->Y)++ oaaee/e-

aaao oi, ia /oi oeacuaaao Y; *P++->Y oaaee/eaaao P iinea au-

ai?ee oiai, ia /oi oeacuaaao Y.

· 133 –

6.3. Ianneau n?oeoo?.

No?oeoo?u iniaaiii iiaeoiaeyo aeey oi?aaeaiey ianneaaie

naycaiiuo ia?aiaiiuo. ?anniio?ei, iai?eia?, i?ia?aiio iiaen-

/aoa /enea aoiaeaeaiee eaaeaeiai eeth/aaiai neiaa ycuea “C”. Iai

ioaeai iannea neiaieueiuo no?ie aeey o?aiaiey eiai e iannea oea-

euo aeey iiaen/aoa. iaeia ec aiciiaeiinoae ninoieo a eniieueciaa-

iee aeaoo ia?aeeaeueiuo ianneaia KEYWORD e KEYCOUNT:

CHAR *KEYWORD [NKEYS];

INT KEYCOUNT [NKEYS];

Ii nai oaeo, /oi ianneau ia?aeeaeueiu, oeacuaaao ia aiciiae-

iinoue ae?oaie i?aaiecaoeee. Eaaeaeia eeth/aaia neiai caeanue ii no-

uanoao yaeyaony ia?ie:

CHAR *KEYWORD;

INT KEYCOUNT;

e, neaaeiaaoaeueii, eiaaony iannea ia?. Iienaiea no?oeoo?u

STRUCT KEY (

CHAR *KEYWORD;

INT KEYCOUNT;

) KEYTAB [NKEYS];

iia?aeaeyao iannea KEYTAB no?oeoo? oaeiai oeia e ioaiaeeo aeey

ieo iaiyoue. Eaaeaeue yeaiaio ianneaa yaeyaony no?oeoo?ie. Yoi

iiaeii auei au caienaoue e oae:

STRUCT KEY (

CHAR *KEYWORD;

INT KEYCOUNT;

);

STRUCT KEY KEYTAB [NKEYS];

Oae eae no?oeoo?a KEYTAB oaeoe/anee niaea?aeeo iinoiyiiue

iaai? eiai, oi eaa/a anaai eieoeeaeece?iaaoue aa iaeei ?ac e

aeey anao /eaiia i?e ii?aaeaeaiee. Eieoeeaeecaoeey no?oeoo?

aiieia aiaeiae/ia i?aaeuaeouei eieoeeaeecaoeeyi – ca ii?aaeaeaie-

ai neaaeoao caeeth/aiiue a oeao?iua neiaee nienie eieoeeaeeca-

oi?ia:

STRUCT KEY (

CHAR *KEYWORD;

INT KEYCOUNT;

) KEYTAB[] =(

“BREAK”, 0,

“CASE”, 0,

“CHAR”, 0,

“CONTINUE”, 0,

“DEFAULT”, 0,

/* … */

“UNSIGNED”, 0,

“WHILE”, 0

);

Eieoeeaeecaoi?u ia?a/eneythony ia?aie niioaaonoaaiii /eaiai

no?oeoo?u. Auei au aieaa oi/ii caeeth/aoue a oeao?iua neiaee

eieoeeaeecaoi?u aeey eaaeaeie “no?iee” eee no?oeoo?u neaaeothuei

ia?acii:

( “BREAK”, 0 ),

( “CASE”, 0 ),

. . .

· 134 –

Ii eiaaea eieoeeaeecaoi?u yaeythony i?inouie ia?aiaiiuie eee

neiaieueiuie no?ieaie e ana iie i?enoonoaotho, oi ai aioo?ai-

ieo oeao?iuo neiaeao iao iaiaoiaeeiinoe. Eae iau/ii, eiiieey-

oi? nai au/eneeo /enei yeaiaioia ianneaa KEYTAB, anee eieoee-

aeecaoi?u i?enoonoaotho, a neiaee [] inoaaeaiu ionouie.

I?ia?aiia iiaen/aoa eeth/aauo neia ia/eiaaony n ii?aaeaea-

iey ianneaa KEYTAB. aaaeouay i?ia?aiia /eoaao naie oaee aai-

aea, iineaaeiaaoaeueii ia?auaynue e ooieoeee GETWORD, eioi?ay ec-

aeaeaao ec aaiaea ii iaeiiio neiao ca ia?auaiea. Eaaeaeia neiai

euaony a ianneaa KEYTAB n iiiiuueth aa?eaioa ooieoeee aeia?iiai

iienea, iaienaiiie iaie a aeaaa 3. (Eiia/ii, /oiau yoa ooie-

oeey ?aaioaea, nienie eeth/aauo neia aeieaeai auoue ?aniieiaeai a

ii?yaeea aic?anoaiey).

#DEFINE MAXWORD 20

MAIN() /* COUNT “C” KEYWORDS */

(

INT N, T;

CHAR WORD[MAXWORD];

WHILE ((T = GETWORD(WORD,MAXWORD)) != EOF)

IF (T == LETTER)

IF((N = BINARY(WORD,KEYTAB,NKEYS)) >= 0)

KEYTAB[N].KEYCOUNT++;

FOR (N =0; N 0)

PRINTF(“%4D %SN”,

KEYTAB[N].KEYCOUNT, KEYTAB[N].KEYWORD);

)

BINARY(WORD, TAB, N) /* FIND WORD IN TAB[0]…TAB[N-1] */

CHAR *WORD;

STRUCT KEY TAB[];

INT N;

(

INT LOW, HIGH, MID, COND;

LOW = 0;

HIGH = N – 1;

WHILE (LOW 0)

LOW = MID + 1;

ELSE

RETURN (MID);

)

RETURN(-1);

)

Iu anei?a i?eaaaeai ooieoeeth GETWORD; iiea aeinoaoi/ii neacaoue,

/oi iia aica?auaao LETTER eaaeaeue ?ac, eae iia iaoiaeeo neiai,

e eiie?oao yoi neiai a naie ia?aue a?aoiaio.

· 135 –

Aaee/eia NKEYS – yoi eiee/anoai eeth/aauo neia a ianneaa

KEYTAB . Oioy iu iiaeai nin/eoaoue yoi /enei a?o/ioth, ai?acaei

eaa/a e iaaeaaeiaa ii?o/eoue yoi iaoeia, iniaaiii a oii neo/aa,

anee nienie eeth/aauo neia iiaeaa?aeai eciaiaieyi. Iaeiie ec

aiciiaeiinoae auei au caeii/eoue nienie eieoeeaeecaoi?ia oeaca-

ieai ia ioeue e caoai i?ieoe a oeeeea neaicue iannea KEYTAB,

iiea ia iaeaeaony eiiaoe.

Ii, iineieueeo ?acia? yoiai ianneaa iieiinoueth ii?aaeaeai e

iiiaioo eiiieeyoeee, caeanue eiaaony aieaa i?inoay aiciiaeiinoue.

*enei yeaiaioia i?inoi anoue

SIZE OF KEYTAB / SIZE OF STRUCT KEY

aeaei a oii, /oi a ycuea “C” i?aaeoniio?aia oia?iay iia?aoeey

SIZEOF, auiieiyaiay ai a?aiy eiiieeyoeee, eioi?ay iicaieyao

au/eneeoue ?acia? ethaiai iauaeoa. Au?aaeaiea

SIZEOF(OBJECT)

auaeaao oeaeia, ?aaiia ?acia?o oeacaiiiai iauaeoa. (?acia? ii-

?aaeaeyaony a ianiaoeeoeoee?iaaiiuo aaeeieoeao, iacuaaaiuo “aae-

oaie”, eioi?ua eiatho oio aea ?acia?, /oi e ia?aiaiiua oeia

CHAR). Iauaeo iiaeao auoue oaeoe/aneie ia?aiaiiie, ianneaii e

no?oeoo?ie, eee eiaiai iniiaiiai oeia, eae INT eee DOUBLE,

eee eiaiai i?iecaiaeiiai oeia, eae no?oeoo?a. A iaoai neo/aa

/enei eeth/aauo neia ?aaii ?acia?o ianneaa, aeaeaiiiio ia ?ac-

ia? iaeiiai yeaiaioa ianneaa. Yoi au/eneaiea eniieuecoaony a

ooaa?aeaeaiee #DEFINE aeey onoaiiaeaiey cia/aiey NKEYS:

#DEFINE NKEYS (SIZEOF(KEYTAB) / SIZEOF(STRUCT KEY))

Oaia?ue ia?aeaeai e ooieoeee GETWORD. Iu oaeoe/anee iaiena-

ee aieaa iauee aa?eaio ooieoeee GETWORD, /ai iaiaoiaeeii aeey

yoie i?ia?aiiu, ii ii ia ia iiiai aieaa neiaeai. Ooieoeey

GETWORD aica?auaao neaaeothuaa “neiai” ec aaiaea, aaea neiaii

n/eoaaony eeai no?iea aoea e oeeo?, ia/eiathueony n aoeau, ee-

ai ioaeaeueiue neiaie. Oei iauaeoa aica?auaaony a ea/aoaa cia-

/aiey ooieoeee; yoi – LETTER, anee iaeaeaii neiai, EOF aeey

eiioea oaeea e nai neiaie, anee ii ia aoeaaiiue.

GETWORD(W, LIM) /* GET NEXT WORD FROM INPUT */

CHAR *W;

INT LIM;

(

INT C, T;

IF (TYPE(C=*W++=GETCH()) !=LETTER) (

*W=’0′;

RETURN©;

)

· 136 –

WHILE (–LIM > 0) (

T = TYPE(C = *W++ = GETCH());

IF (T ! = LETTER && T ! = DIGIT) (

UNGETCH©;

BREAK;

)

)

*(W-1) – ‘0’;

RETURN(LETTER);

)

Ooieoeey GETWORD eniieuecoao ooieoeee GETCH e UNGETCH, eioi?ua

iu iaienaee a aeaaa 4: eiaaea iaai? aeoaaeoiuo neiaieia i?a-

?uaaaony, ooieoeey GETWORD iieo/aao iaeei eeoiee neiaie. A ?a-

coeueoaoa auciaa UNGETCH yoio neiaie iiiauaaony iacaae ai aaiae

aeey neaaeothuaai ia?auaiey.

Ooieoeey GETWORD ia?auaaony e ooieoeee TYPE aeey ii?aaeaea-

iey oeia eaaeaeiai ioaeaeueiiai neiaiea ec oaeea aaiaea. Aio aa-

?eaio, ni?aaaaeeeaue oieueei aeey aeoaaeoa ASCII.

TYPE© /* RETURN TYPE OF ASCII CHARACTER */ INT C;

(

IF (C>= ‘A’ && C= ‘A’ && C= ‘0’ && CKEYCOUNT++;

FOR (P=KEYTAB; P>KEYTAB + NKEYS; P++)

IF (P->KEYCOUNT > 0)

PRINTF(“%4D %S/N”, P->KEYCOUNT, P->KEYWORD);

)

STRUCT KEY BINARY(WORD, TAB, N) / FIND WORD */

CHAR WORD / IN TAB[0]…TAB[N-1] */

STRUCT KEY TAB [];

INT N;

(

INT COND;

STRUCT KEY *LOW = &TAB[0];

STRUCT KEY *HIGH = &TAB[N-1];

STRUCT KEY *MID;

WHILE (LOW KEYWORD)) 0)

LOW = MID + 1;

ELSE

RETURN(MID);

)

RETURN(NULL);

)

Caeanue eiaaony ianeieueei iiiaioia, eioi?ua noieo ioia-

oeoue. Ai-ia?auo, iienaiea ooieoeee BINARI aeieaeii oeacuaaoue,

/oi iia aica?auaao oeacaoaeue ia no?oeoo?o oeia KEY, a ia ia

oeaeia; yoi iauyaeyaony eae a ooieoeee MAIN, oae e a BINARY.

Anee ooieoeey BINARI iaoiaeeo neiai, oi iia aica?auaao oeaca-

oaeue ia iaai; anee aea iao, iia aica?auaao NULL.

· 138 –

Ai-aoi?uo, ana ia?auaiey e yeaiaioai ianneaa KEYTAB ino-

uanoaeythony /a?ac oeacaoaee. Yoi aea/ao ca niaie iaeii nouan-

oaaiiia eciaiaiea a ooieoeee BINARY: n?aaeiee yeaiaio aieueoa

iaeuecy au/eneyoue i?inoi ii oi?ioea

MID = (LOW + HIGH) / 2

iioiio /oi neiaeaiea aeaoo oeacaoaeae ia aeaao eaeiai-ieaoaeue

iieaciiai ?acoeueoaoa (aeaaea iinea aeaeaiey ia 2) e a aeaenoae-

oaeueiinoe yaeyaony iacaeiiiui. yoo oi?ioeo iaaei caiaieoue ia

MID = LOW + (HIGH-LOW) / 2

a ?acoeueoaoa eioi?ie MID noaiiaeony oeacaoaeai ia yeaiaio,

?aniieiaeaiiue iina?aaeeia iaaeaeo LOW e HIGH.

Aai oaeaea neaaeoao ?acia?aoueny a eieoeeaeecaoeee LOW e

HIGH. oeacaoaeue iiaeii eieoeeaeece?iaaoue aae?anii ?aiaa ii?aaea-

eaiiiai iauaeoa; eiaiii eae iu caeanue e iinooieee.

A ooieoeee MAIN iu iaienaee

FOR (P=KEYTAB; P WORD = STRSAVE(W);

P->COUNT = 1;

P->LEFT = P->RIGHT = NULL;

) ELSE IF ((COND = STRCMP(W, P->WORD)) == 0)

P->COUNT++; /* REPEATED WORD */

ELSE IF (COND LEFT = TREE(P->LEFT, W);

ELSE /* GREATER INTO RIGHT SUBTREE */

P->RIGHT = TREE(P->RIGHT, W);

RETURN(P);

)

· 141 –

Iaiyoue aeey iiaiai ocea auaeaeyaony ooieoeeae TALLOC, yaey-

thuaeny aaeaioaoeeae aeey aeaiiiai neo/ay ooieoeee ALLOC, iaienai-

iie iaie ?aiaa. Iia aica?auaao oeacaoaeue naiaiaeiiai i?ino-

?ainoaa, i?eaiaeiiai aeey o?aiaiey iiaiai ocea aea?aaa. (Iu

anei?a ianoaeei yoi iiae?iaiaa). Iiaia neiai eiie?oaony ooie-

oeeae STRSAVE a ne?uoia ianoi, n/ao/ee eieoeeaeece?oaony aaee-

ieoeae, e oeacaoaee iaieo iioiieia iieaaathony ?aaiuie ioeth.

Yoa /anoue i?ia?aiiu auiieiyaony oieueei i?e aeiaaaeaiee iiaiai

ocea e ?aa?o aea?aaa. Iu caeanue iionoeee i?iaa?eo ia ioeaee

aica?auaaiuo ooieoeee STRSAVE e TALLOC cia/aiee (/oi ia?acoi-

ii aeey i?aeoe/anee ?aaioathuae i?ia?aiiu).

Ooieoeey TREEPRINT ia/aoaao aea?aai, ia/eiay n eaaiai iiae-

aea?aaa; a eaaeaeii ocea nia/aea ia/aoaaony eaaia iiaeaea?aai

(ana neiaa, eioi?ua ieaaeoa yoiai neiaa), caoai naii neiai, a

caoai i?aaia iiaeaea?aai (ana neiaa, eioi?ua noa?oa). Anee au

iaoaa?aiii iia?e?oaoa n ?aeo?neae, ia?enoeoa aea?aai naie e

iaia/aoaeoa aai n iiiiuueth ooieoeee TREEPRINT ; yoi iaeia ec

iaeaieaa yniuo ?aeo?neaiuo i?ioeaaeo?, eioi?oth iiaeii iaeoe.

TREEPRINT (P) /* PRINT TREE P RECURSIVELY */

STRUCT TNODE *P;

(

IF (P != NULL) (

TREEPRINT (P->LEFT);

PRINTF(“%4D %SN”, P->COUNT, P->WORD);

TREEPRINT (P->RIGHT);

)

)

I?aeoe/aneia caia/aiea: anee aea?aai noaiiaeony “ianaa-

eaine?iaaiiui” ec-ca oiai, /oi neiaa iinooiatho ia a neo/ae-

iii ii?yaeea, oi a?aiy ?aaiou i?ia?aiiu iiaeao ?anoe neeoeii

auno?i. A ooaeoai neo/aa, eiaaea iinooiathuea neiaa oaea oii?y-

aei/aiu, ianoiyuay i?ia?aiia inouanoaeyao aei?iainoiyuoth eie-

oaoeeth eeiaeiiai iienea. Nouanoaotho ?acee/iua iaiauaiey aeai-

e/iiai aea?aaa, iniaaiii 2-3 aea?aauey e AVL aea?aauey, eioi?ua

ia aaaeoo naay oae “a ooaeoeo neo/ayo”, ii iu ia aoaeai caeanue

ia ieo inoaiaaeeaaoueny.

I?aaeaea /ai ?annoaoueny n yoei i?eia?ii, oianoii naeaeaoue

iaaieueoia ionooieaiea a nayce n aii?inii i ?ani?aaeaeaiee ia-

iyoe. ssnii, /oi a i?ia?aiia aeaeaoaeueii eiaoue oieueei iaeei

?ani?aaeaeeoaeue iaiyoe, aeaaea anee aio i?eoiaeeony ?aciauaoue

?acee/iua aeaeu iauaeoia. Ii anee iu oioei eniieueciaaoue iaeei

?ani?aaeaeeoaeue iaiyoe aeey ia?aaioee cai?inia ia auaeaeaiea

iaiyoe aeey oeacaoaeae ia ia?aiaiiua oeia CHAR e aeey oeacaoa-

eae ia STRUCT TNODE, oi i?e yoii aicieeatho aeaa aii?ina. Ia?-

aue: eae auiieieoue oi nouanoaothuaa ia aieueoeinoaa ?aaeueiuo

iaoei ia?aie/aiea, /oi iauaeou ii?aaeaeaiiuo oeiia aeieaeiu

oaeiaeaoai?youe o?aaiaaieyi au?aaieaaiey (iai?eia?, /anoi oea-

eua aeieaeiu ?aciauaoueny a /aoiuo aae?anao)? Aoi?ie: eae i?aa-

ieciaaoue iienaiey, /oiau ni?aaeoueny n oai, /oi ooieoeey ALLOC

aeieaeia aica?auaoue ?acee/iua aeaeu oeacaoaeae ?

· 142 –

Aiiaua aiai?y, o?aaiaaiey au?aaieaaiey eaaei auiieieoue

ca n/ao auaeaeaiey iaeioi?iai eeoiaai i?ino?ainoaa, i?inoi

iaania/ea oi, /oiau ?ani?aaeaeeoaeue iaiyoe anaaaea aica?auae

oeacaoaeue, oaeiaeaoai?ythuee anai ia?aie/aieyi au?aaieaaiey.

Iai?eia?, ia PDP-11 aeinoaoi/ii, /oiau ooieoeey ALLOC anaaaea

aica?auaea /aoiue oeacaoaeue, iineieueeo a /aoiue aae?an iiaeii

iiianoeoue ethaie oei iauaeoa. aaeeinoaaiiue ?anoiae i?e yoii –

eeoiee neiaie i?e cai?ina ia ia/aoioth aeeeio. Aiaeiae/iua

aeaenoaey i?aaei?eieiathony ia ae?oaeo iaoeiao. Oaeei ia?acii,

?aaeecaoeey ALLOC iiaeao ia ieacaoueny ia?aiineiie, ii aa en-

iieueciaaiea aoaeao ia?aiineiui. Ooieoeey ALLOC ec aeaau 5 ia

i?aaeoniao?eaaao ieeaeiai ii?aaeaeaiiiai au?aaieaaiey; a aeaaa

8 iu i?iaeaiiino?e?oai, eae i?aaeeueii auiieieoue yoo caaea/o.

Aii?in iienaiey oeia ooieoeee ALLOC yaeyaony io/eoaeueiui

aeey ethaiai ycuea, eioi?ue na?ueacii ioiineony e i?iaa?ea oe-

iia. Eo/oee niinia a ycuea “C” – iauyaeoue, /oi ALLOC aica?a-

uaao oeacaoaeue ia ia?aiaiioth oeia CHAR, a caoai yaii i?aia-

?aciaaoue yoio oeacaoaeue e aeaeaaiiio oeio n iiiiuueth iia?aoeee

ia?aaiaea oeiia. Oaeei ia?acii, anee iienaoue P a aeaea

CHAR *P;

oi

(STRUCT TNODE *) P

i?aia?acoao aai a au?aaeaieyo a oeacaoaeue ia no?oeoo?o oeia TNODE .
Neaaeiaaoaeueii, ooieoeeth TALLOC iiaeii caienaoue a aeaea:

STRUCT TNODE *TALLOC()

(

CHAR *ALLOC();

RETURN ((STRUCT TNODE *) ALLOC(SIZEOF(STRUCT TNODE)));

)

yoi aieaa /ai aeinoaoi/ii aeey ?aaioathueo a ianoiyuaa a?aiy

eiiieeyoi?ia, ii yoi e naiue aaciianiue iooue n o/aoii aoaeoth-

uaai.

Oi?aaeiaiea 6-4.

Iaieoeoa i?ia?aiio, eioi?ay /eoaao “C”-i?ia?aiio e ia/a-

oaao a aeoaaeoiii ii?yaeea eaaeaeoth a?oiio eiai ia?aiaiiuo, ei-

oi?ua niaiaaeatho a ia?auo naie neiaieao, ii ioee/athony aaea-oi

aeaeueoa. (Naeaeaeoa oae, /oiau 7 auei ia?aiao?ii).

Oi?aaeiaiea 6-5.

Iaieoeoa i?ia?aiio auaea/e ia?ae?anoiuo nnueie, o.a.

I?ia?aiio, eioi?ay ia/aoaao nienie anao neia aeieoiaioa e aeey

eaaeaeiai ec yoeo neia ia/aoaao nienie iiia?ia no?ie, a eioi-

?ua yoi neiai aoiaeeo.

Oi?aaeiaiea 6-6.

Iaieoeoa i?ia?aiio, eioi?ay ia/aoaao neiaa ec naiaai

oaeea aaiaea, ?aniieiaeaiiua a ii?yaeea oauaaiey /anoiou eo ii-

yaeaiey. Ia?aae eaaeaeui neiaii iaia/aoaeoa /enei aai iiyaea-

iee.

· 143 –

6.6. Iiene a oaaeeoea.

Aeey eeethno?aoeee aeaeueiaeoeo aniaeoia eniieueciaaiey no?oe-

oo? a yoii ?acaeaea iu iaieoai i?ia?aiio, i?aaenoaaeythuoth ni-

aie niaea?aeeiia iaeaoa iienea a oaaeeoea. Yoa i?ia?aiia yaey-

aony oeie/iui i?aaenoaaeoaeai iiaei?ia?aii oi?aaeaiey neiaieue-

iuie oaaeeoeaie iae?ii?ioeanni?a eee eiiieeyoi?a. ?anniio?ei,

iai?eia?, iia?aoi? #DEFINE ycuea “C”. Eiaaea ano?a/aaony

no?iea aeaea

#DEFINE YES 1

oi eiy YES e caiaiythuee oaeno 1 iiiauathony a oaaeeoeo. Iicae-

iaa, eiaaea eiy YES iiyaeyaony a iia?aoi?a aeaea

INWORD = YES;

Oii aeieaeii auoue caiauaii ia 1.

Eiathony aeaa iniiaiua i?ioeaaeo?u, eioi?ua oi?aaeytho eiaia-

ie e caiaiythueie eo oaenoaie. Ooieoeey INSTALL(S,T) caienuaa-

ao eiy S e caiaiythuee oaeno T a oaaeeoeo; caeanue S e T i?inoi

neiaieueiua no?iee. Ooieoeey LOOKUP(S) euao eiy S a oaaeeoea e

aica?auaao eeai oeacaoaeue oiai ianoa, aaea yoi eiy iaeaeaii,

eeai NULL, anee yoiai eiaie a oaaeeoea ia ieacaeinue.

I?e yoii eniieuecoaony iiene ii aeai?eoio oaoe?iaaiey –

iinooiathuaa eiy i?aia?acoaony a iaeaiueeia iieiaeeoaeueiia /en-

ei, eioi?ia caoai eniieuecoaony aeey eiaeaenaoeee ianneaa oeaca-

oaeae. Yeaiaio ianneaa oeacuaaao ia ia/aei oeaii/iuo aeieia,

iienuaathueo eiaia, eioi?ua eiatho yoi cia/aiea oaoe?iaaiey.

Anee ieeaeea eiaia i?e oaoe?iaaiee ia iieo/atho yoiai cia/a-

iey, oi yeaiaioii ianneaa aoaeao NULL.

Aeieii oeaie yaeyaony no?oeoo?a, niaea?aeauay oeacaoaee ia

niioaaonoaothuaa eiy, ia caiaiythuee oaeno e ia neaaeothuee aeie

a oeaie. Ioeaaie oeacaoaeue neaaeothuaai aeiea neoaeeo i?eciaeii

eiioea aeaiiie oeaie.

STRUCT NLIST ( /* BASIC TABLE ENTRY */

CHAR *NAME;

CHAR *DEF;

STRUCT NLIST NEXT; / NEXT ENTRY IN CHAIN */

);

Iannea oeacaoaeae yoi i?inoi

DEFINE HASHSIZE 100

TATIC STRUCT NLIST HASHTAB[HASHSIZE] / POINTER TABLE */

Cia/aiea ooieoeee oaoe?iaaiey, eniieuecoaiie iaaeie ooie-

oeeyie LOOKUP e INSTALL , iieo/aaony i?inoi eae inoaoie io

aeaeaiey noiiu neiaieueiuo cia/aiee no?iee ia ?acia? ianneaa.

(Yoi ia naiue eo/oee aiciiaeiue aeai?eoi, ii aai aeinoieinoai

ninoieo a eneeth/eoaeueiie i?inoioa).

· 144 –

HASH(S) /* FORM HASH VALUE FOR STRING */

CHAR *S;

(

INT HASHVAL;

FOR (HASHVAL = 0; *S != ‘0’; )

HASHVAL += *S++;

RETURN(HASHVAL % HASHSIZE);

)

A ?acoeueoaoa i?ioeanna oaoe?iaaiey auaeaaony ia/aeueiue ei-

aeaen a ianneaa HASHTAB ; anee aeaiiay no?iea iiaeao auoue

aaea-oi iaeaeaia, oi eiaiii a oeaie aeieia, ia/aei eioi?ie oea-

caii oai. Iiene inouanoaeyaony ooieoeeae LOOKUP. Anee ooieoeey

LOOKUP iaoiaeeo, /oi aeaiiue yeaiaio oaea i?enoonoaoao, oi iia

aica?auaao oeacaoaeue ia iaai; anee iao, oi iia aica?auaao

NULL.

STRUCT NLIST LOOKUP(S) / LOOK FOR S IN HASHTAB */

CHAR *S;

(

STRUCT NLIST *NP;

FOR (NP = HASHTAB[HASH(S)]; NP != NULL;NP=NP->NEXT)

IF (STRCMP(S, NP->NAME) == 0)

RETURN(NP); /* FOUND IT */

RETURN(NULL); /* NOT FOUND */

Ooieoeey INSTALL eniieuecoao ooieoeeth LOOKUP aeey ii?aaeaea-

iey, ia i?enoonoaoao ee oaea aaiaeeiia a aeaiiue iiiaio eiy;

anee yoi oae, oi iiaia ii?aaeaeaiea aeieaeii auoanieoue noa?ia.

A i?ioeaiii neo/aa nicaeaaony niaa?oaiii iiaue yeaiaio. Anee

ii eaeie-eeai i?e/eia aeey iiaiai yeaiaioa aieueoa iao ianoa,

oi ooieoeey INSTALL aica?auaao NULL.

STRUCT NLIST INSTALL(NAME, DEF) / PUT (NAME, DEF) */

CHAR *NAME, *DEF;

(

STRUCT NLIST *NP, *LOOKUP();

CHAR *STRSAVE(), *ALLOC();

INT HASHVAL;

IF((NP = LOOKUP(NAME)) == NULL) ( /* NOT FOUND */

NP = (STRUCT NLIST *) ALLOC(SIZEOF(*NP));

IF (NP == NULL)

RETURN(NULL);

IF ((NP->NAME = STRSAVE(NAME)) == NULL)

RETURN(NULL);

HASHVAL = HASH(NP->NAME);

NP->NEXT = HASHTAB[HASHVAL];

HASHTAB[HASHVAL] = NP;

) ELSE /* ALREADY THERE */

FREE((NP->DEF);/* FREE PREVIOUS DEFINITION */

IF ((NP->DEF = STRSAVE(DEF)) == NULL)

RETURN (NULL);

RETURN(NP);

)

· 145 –

Ooieoeey STRSAVE i?inoi eiie?oao no?ieo, oeacaiioth a ea-

/anoaa a?aoiaioa, a ianoi o?aiaiey, iieo/aiiia a ?acoeueoaoa

ia?auaiey e ooieoeee ALLOC. Iu oaea i?eaaee yoo ooieoeeth a aea-

aa 5. Oae eae ia?auaiea e ooieoeee ALLOC e FREE iiaoo i?ien-

oiaeeoue a ethaii ii?yaeea e a nayce n i?iaeaiie au?aaieaaiey,

i?inoie aa?eaio ooieoeee ALLOC ec aeaau 5 iai aieueoa ia iiae-

oiaeeo; niio?eoa aeaau 7 e 8.

Oi?aaeiaiea 6-7.

Iaieoeoa i?ioeaaeo?o, eioi?ay aoaeao oaeaeyoue eiy e ii?aaea-

eaiea ec oaaeeoeu, oi?aaeyaiie ooieoeeyie LOOKUP e INSTALL.

Oi?aaeiaiea 6-8.

?ac?aaioaeoa i?inooth, iniiaaiioth ia ooieoeeyo yoiai ?ac-

aeaea, aa?neth i?ioeanni?a aeey ia?aaioee eiino?oeoeee #DEFINE ,

i?eaiaeioth aeey eniieueciaaiey n “C”-i?ia?aiiaie. Aai iiaoo

oaeaea ieacaoueny iieaciuie ooieoeee GETCHAR e UNGETCH.

6.7. Iiey.

Eiaaea aii?in yeiiiiee iaiyoe noaiiaeony i/aiue nouanoaai-

iui, oi iiaeao ieacaoueny iaiaoiaeeiui iiiauaoue a iaeii iaoeiiia

neiai ianeieueei ?acee/iuo iauaeoia; iaeii ec iniaaiii ?ani-

?in?aiaiiuo oiio?aaeaiee – iaai? iaeiiaeoiauo i?eciaeia a

i?eiaiaieyo, iiaeiaiuo neiaieueiui oaaeeoeai eiiieeyoi?a. aiao-

ia iaoneiaeaiiua oi?iaou aeaiiuo, oaeea eae eioa?oaenu aiia-

?aoiuo n?aaenoa oaeaea ca/anooth i?aaeiieaaatho aiciiaeiinoue iieo-

/aiey neiaa ii /anoyi.

I?aaenoaaueoa naaa o?aaiaio eiiieeyoi?a, eioi?ue ?aaioaao

n neiaieueiie oaaeeoeae. N eaaeaeui eaeaioeoeeaoi?ii i?ia?aiiu

naycaia ii?aaeaeaiiay eioi?iaoeey, iai?eia?, yaeyaony ii eee

iao eeth/aaui neiaii, yaeyaony ee ii eee iao aiaoiei e/eee

noaoe/aneei e o.ae. Naiue eiiiaeoiue niinia caeiaee?iaaoue oa-

eoth eioi?iaoeeth – iiianoeoue iaai? iaeiiaeoiauo i?eciaeia a io-

aeaeueioth ia?aiaiioth oeia CHAR eee INT.

Iau/iue niinia, eioi?ui yoi aeaeaaony, ninoieo a ii?aaea-

eaiee iaai?a “ianie”, ioaa/athueo niioaaonoaouei aeoiaui ii-

ceoeeyi, eae a

#DEFINE KEYWORD 01

#DEFINE EXTERNAL 02

#DEFINE STATIC 04

(/enea aeieaeiu auoue noaiaiyie aeaieee). Oiaaea ia?aaioea aeoia

naaaeaony e “aeiiaee?iaaieth aeoaie” n iiiiuueth iia?aoeee naeaeaa,

ianee?iaaiey e aeiiieiaiey, iienaiiuo iaie a aeaaa 2.

Iaeioi?ua /anoi ano?a/athueany eaeeiiu:

FLAGS != EXTERNAL ! STATIC;

aeeth/aao aeou EXTERNAL e STATIC a FLAGS, a oi a?aiy eae

FLAGS &= ^(aXTERNAL ! STATIC);

· 146 –

eo aueeth/aao, a

IF ((FLAGS & (EXTERNAL ! STATIC)) == 0) …

enoeiii, anee iaa aeoa aueeth/aiu.

Oioy yoeie eaeeiiaie eaaei iaeaaeaoue, ycue “C” a ea/anoaa

aeueoa?iaoeau i?aaeeaaaao aiciiaeiinoue ii?aaeaeaiey e ia?aaioee

iieae aioo?e neiaa iaiin?aaenoaaiii, a ia iin?aaenoaii iiaeoi-

auo eiae/aneeo iia?aoeee. Iiea – yoi iaai? niaaeiuo aeoia

aioo?e iaeiie ia?aiaiiie oeia INT. Neioaenen ii?aaeaeaiey e

ia?aaioee iieae iniiauaaaony ia no?oeoo?ao. Iai?eia?, nei-

aieueioth oaaeeoeo eiino?oeoeee #DEFINE, i?eaaaeaiioth auoa, iiaeii

au auei caiaieoue ii?aaeaeaieai o?ao iieae:

STRUCT (

UNSIGNED IS_KEYWORD : 1;

UNSIGNED IS_EXTERN : 1;

UNSIGNED IS_STATIC : 1;

) FLAGS;

Caeanue ii?aaeaeyaony ia?aiaiiay n eiaiai FLAGS, eioi?ay niaea?-

aeeo o?e 1-aeoiauo iiey. Neaaeothuaa ca aeaiaoi/eai /enei caaeaao

oe?eio iiey a aeoao. Iiey iienaiu eae UNSIGNED, /oiau iiae-

/a?eiooue, /oi iie aeaenoaeoaeueii aoaeoo aaee/eiaie aac ciaea.

Ia ioaeaeueiua iiey iiaeii nnueaoueny, eae FLAGS.IS_STATIE,

FLAGS. IS_EXTERN, FLAGS.IS_KEYWORD E o.ae., oi anoue oi/ii oae

aea, eae ia ae?oaea /eaiu no?oeoo?u. Iiey aaaeoo naay iiaeiaii

iaaieueoei oeaeui aac ciaea e iiaoo o/anoaiaaoue a a?eoiaoe/an-

eeo au?aaeaieyo oi/ii oae aea, eae e ae?oaea oeaeua. Oaeei ia?a-

cii, i?aaeuaeouea i?eia?u aieaa anoanoaaiii ia?aienaoue oae:

FLAGS.IS_EXTERN = FLAGS.IS_STATIC = 1;

aeey aeeth/aiey aeoia;

FLAGS.IS_EXTERN = FLAGS.IS_STATIC = 0;

aeey aueeth/aiey aeoia;

IF (FLAGS.IS_EXTERN == 0 &&FLAGS.IS_STATIC == 0)…

aeey eo i?iaa?ee.

Iiea ia iiaeao ia?ae?uaaoue a?aieoeo INT; anee oeacaiiay

oe?eia oaeiaa, /oi yoi aeieaeii neo/eoueny, oi iiea au?aaieaa-

aony ii a?aieoea neaaeothuaai INT. Iieyi iiaeii ia i?enaaeaaoue

eiaia; iaeiaiiaaiiua iiey (oieueei aeaiaoi/ea e oe?eia) en-

iieuecothony aeey caiieiaiey naiaiaeiiai ianoa. *oiau auioaeeoue

au?aaieaaiea ia a?aieoeo neaaeothuaai INT, iiaeii eniieueciaaoue

niaoeeaeueioth oe?eio 0.

· 147 –

I?e ?aaioa n iieyie eiaaony ?yae iiiaioia, ia eioi?ua

neaaeoao ia?aoeoue aieiaiea. Ii-aeaeeiiio iaeaieaa nouanoaaiiui

yaeyaony oi, /oi io?aaeay i?e?iaeo ?acee/iuo aiia?aoiuo n?aae-

noa, ?ani?aaeaeaiea iieae ia iaeioi?uo iaoeiao inouanoaeyaony

neaaa iai?aai, a ia iaeioi?uo ni?aaa iaeaai. Yoi icia/aao,

/oi oioy iiey i/aiue iieaciu aeey ?aaiou n aioo?aiia ii?aaea-

eaiiuie no?oeoo?aie aeaiiuo, i?e ?acaeaeaiee aiaoia ii?aaeaeya-

iuo aeaiiuo neaaeoao ouaoaeueii ?anniao?eaaoue aii?in i oii, ea-

eie eiiaoe iinooiaao ia?aui.

Ae?oaea ia?aie/aiey, eioi?ua neaaeoao eiaoue a aeaeo: iiey

ia eiatho ciaea; iie iiaoo o?aieoueny oieueei a ia?aiaiiuo oeia

INT (eee, /oi yeaeaaeaioii, oeia UNSIGNED); iie ia yaeythony

ianneaaie; iie ia eiatho aae?ania, oae /oi e iei ia i?eiaieia

iia?aoeey &.

6.8. Iauaaeeiaiey.

Oauaaeeiaiey – yoi ia?aiaiiay, eioi?ay a ?acee/iua iiiai-

ou a?aiaie iiaeao niaea?aeaoue iauaeou ?aciuo oeiia e ?acia?ia,

i?e/ai eiiieeyoi? aa?ao ia naay ioneaaeeaaiea ?acia?a e o?a-

aiaaiee au?aaieaaiey. Iauaaeeiaiey i?aaenoaaeytho aiciiaeiinoue

?aaioaoue n ?acee/iuie aeaeaie aeaiiuo a iaeiie iaeanoe iaiyoe,

ia aaiaey a i?ia?aiio ieeaeie iaoeiii-caaeneiie eioi?iaoeee.

A ea/anoaa i?eia?a, niiaa ec neiaieueiie oaaeeoeu eiiieey-

oi?a, i?aaeiieiaeei, /oi eiinoaiou iiaoo auoue oeia INT , FLOAT

eee auoue oeacaoaeyie ia neiaieu. cia/aiea eaaeaeie eiie?aoiie

eiinoaiou aeieaeii o?aieoueny a ia?aiaiiie niioaanoaothuaai oe-

ia, ii ana aea aeey oi?aaeaiey oaaeeoeae naiui oaeiaiui auei au,

anee yoi cia/aiea caieiaei au iaeei e oio aea iauai iaiyoe e

o?aieeinue a oii aea naiii ianoa iacaaeneii io aai oeia. yoi e

yaeyaony iacia/aieai iauaaeeiaiey – auaeaeeoue ioaeaeueioth ia?a-

iaiioth, a eioi?ie iiaeii caeiiii o?aieoue ethaoth iaeio ec ia?a-

iaiiuo ianeieueeeo oeiia. Eae e a neo/aa iieae, neioaenen in-

iiauaaaony ia no?oeoo?ao.

UNION U_TAG (

INT IVAL;

FLOAT FVAL;

CHAR *PVAL;

) UVAL;

Ia?aiaiiay UVAL aoaeao eiaoue aeinoaoi/ii aieueoie ?acia?,/oiau

o?aieoue iaeaieueoee ec o?ao oeiia, iacaaeneii io iaoeiu, ia

eioi?ie inouanoaeyaony eiiieeyoeey, – i?ia?aiia ia aoaeao ca-

aeneoue io oa?aeoa?enoee aiia?aoiuo n?aaenoa. Ethaie ec yoeo

o?ao oeiia iiaeao auoue i?enaiai UVAR e caoai eniieueciaai a

au?aaeaieyo, iiea oaeia eniieueciaaiea niaianoeii: ecaeaeaaiue

oei aeieaeai niaiaaeaoue n iineaaeiei iiiauaiiui oeiii. Aeaei

i?ia?aiienoa – neaaeeoue ca oai, eaeie oei o?aieony a iauaaee-

iaiee a aeaiiue iiiaio; anee /oi-eeai o?aieony eae iaeei oei,

a ecaeaeaaony eae ae?oaie, oi ?acoeueoaou aoaeoo caaenaoue io

eniieuecoaiie iaoeiu.

· 149 –

Neioaene/anee aeinooi e /eaiai iauaaeeiaiey inouanoaeyaony

neaaeothuei ia?acii:

eiy iauaaeeiaiey./eai

eee

oeacaoaeue iauaaeeiaiey ->/eai

oi anoue oi/ii oae aea, eae e a neo/aa no?oeoo?. anee aeey ion-

eaaeeaaiey oeia, o?aieiiai a aeaiiue iiiaio a UVAL, eniieueco-

aony ia?aiaiiay UTYPE, oi iiaeii ano?aoeoue oaeie o/anoie

i?ia?aiiu:

IF (UTYPE == INT)

PRINTF(“%DN”, UVAL.IVAL);

ELSE IF (UTYPE == FLOAT)

PRINTF(“%FN”, UVAL.FVAL);

ELSE IF (UTYPE == STRING)

PRINTF(“%SN”, UVAL.PVAL);

ELSE

PRINTF(“BAD TYPE %D IN UTYPEN”, UTYPE);

Iauaaeeiaiey iiaoo iiyaeyoueny aioo?e no?oeoo? e ianneaia

e iaiai?io. Caienue aeey ia?auaiey e /eaio iauaaeeiaiey a

no?oeoo?a (eee iaiai?io) niaa?oaiii eaeaioe/ia oie, eioi?ay

eniieuecoaony ai aeiaeaiiuo no?oeoo?ao. iai?eia?, a ianneaa

no?oeoo?, ii?aaeaeaiiui neaaeothuei ia?acii

STRUCT (

CHAR *NAME;

INT FLAGS;

INT UTYPE;

UNION (

INT IVAL;

FLOAT FVAL;

CHAR *PVAL;

) UVAL;

) SYMTAB[NSYM];

ia ia?aiaiioth IVAL iiaeii nineaoueny eae

SYMTAB[I].UVAL.IVAL

a ia ia?aue neiaie no?iee PVAL eae

*SYMTAB[I].UVAL.PVAL

A nouiinoe iauaaeeiaiea yaeyaony no?oeoo?ie, a eioi?ie ana

/eaiu eiatho ioeaaia niauaiea. Naia no?oeoo?a aeinoaoi/ii aa-

eeea, /oiau o?aieoue “naiue oe?ieee” /eai, e au?aaieaaiea

i?eaiaeii aeey anao oeiia, aoiaeyueo a iauaaeeiaiea. Eae e a

neo/aa no?oeoo?, aaeeinoaaiiuie iia?aoeeyie, eioi?ua a ianoiy-

uaa a?aiy iiaeii i?iaiaeeoue n iauaaeeiaieyie, yaeythony aeinooi e

· 150 –

/eaio e ecaea/aiea aae?ana; iauaaeeiaiey ia iiaoo auoue i?enai-

aiu, ia?aaeaiu ooieoeeyi eee aica?auaiu eie. oeacaoaee iauaaee-

iaiee iiaeii eniieueciaaoue a oi/ii oaeie aea iaia?a, eae e oea-

caoaee no?oeoo?.

I?ia?aiia ?ani?aaeaeaiey iaiyoe, i?eaiaeeiay a aeaaa 8 ,

iieacuaaao, eae iiaeii eniieueciaaoue iauaaeeiaiea, /oiau naea-

eaoue iaeioi?oth ia?aiaiioth au?iaiaiiie ii ii?aaeaeaiiiio aeaeo

a?aieoeu iaiyoe.

6.9. Ii?aaeaeaiea oeia

A ycuea “C” i?aaeoniio?aia aiciiaeiinoue, iacuaaaiay TYPEDEF

aeey aaaaeaiey iiauo eiai aeey oeiia aeaiiuo. Iai?eia?, iienaiea

TYPEDEF INT LENGTH;

aeaeaao eiy LENGTH neiiieiii aeey INT. “Oei” LENGTH iiaeao auoue
eniieueciaai a iienaieyo, ia?aaiaeia oeiia e o.ae. Oi/ii oaeei aea
ia?acii, eae e oei INT:

LENGTH LEN, MAXLEN;

LENGTH *LENGTHS[];

Aiaeiae/ii iienaieth

TYPEDEF CHAR *STRING;

aeaeaao STRING neiiieiii aeey CHAR*, oi anoue aeey oeacaoaey ia

neiaieu, /oi caoai iiaeii eniieueciaaoue a iienaieyo aeaea

STRING P, LINEPTR[LINES], ALLOC();

Ia?aoeoa aieiaiea, /oi iauyaeyaiue a eiino?oeoeee TYPEDEF

oei iiyaeyaony a iiceoeee eiaie ia?aiaiiie, a ia n?aco ca

neiaii TYPEDEF. Neioaene/anee eiino?oeoeey TYPEDEF iiaeiaia

iienaieyi eeanna iaiyoe EXTERN, STATIC e o. Ae. iu oaeaea en-

iieueciaaee i?iieniua aoeau, /oiau yniaa auaeaeeoue eiaia.

A ea/anoaa aieaa neiaeiiai i?eia?a iu eniieuecoai eiino-

?oeoeeth TYPEDEF aeey iienaiey oceia aea?aaa, ?anniio?aiiuo ?a-

iaa a yoie aeaaa:

TYPEDEF STRUCT TNODE ( /* THE BASIC NODE */

CHAR WORD; / POINTS TO THE TEXT */

INT COUNT; /* NUMBER OF OCCURRENCES */

STRUCT TNODE LEFT; / LEFT CHILD */

STRUCT TNODE RIGHT; / RIGHT CHILD */

) TREENODE, *TREEPTR;

A ?acoeueoaoa iieo/aai aeaa iiauo eeth/aauo neiaa: TREENODE

(no?oeoo?a) e TREEPTR (oeacaoaeue ia no?oeoo?o). Oiaaea ooie-

oeeth TALLOC iiaeii caienaoue a aeaea

· 151 –

TREEPTR TALLOC()

(

CHAR *ALLOC();

RETURN((TREEPTR) ALLOC(SIZEOF(TREENODE)));

)

Iaiaoiaeeii iiae/a?eiooue, /oi iienaiea TYPEDEF ia i?eaiaeeo

e nicaeaieth iiaiai a eaeii-eeai niunea oeia; iii oieueei aei-

aaaeyao iiaia eiy aeey iaeioi?iai nouanoaothuaai oeia. i?e

yoii ia aicieeaao e ieeaeie iiaie naiaioeee: iienaiiua oaeei

niiniaii ia?aiaiiua iaeaaeatho oi/ii oaie aea naienoaaie, /oi e

ia?aiaiiua, iienaiiua yaiui ia?acii. Ii nouanoao eiino?oeoeey

TYPEDEF noiaeia n #DEFINE ca eneeth/aieai oiai, /oi iia eioa?-

i?aoe?oaony eiiieeyoi?ii e iioiio iiaeao inouanoaeyoue iiaenoa-

iiaee oaenoa, eioi?ua auoiaeyo ca i?aaeaeu aiciiaeiinoae iae-

?ii?ioeanni?a ycuea “C”. Iai?eia?,

TYPEDEF INT (*PFI) ();

nicaeaao oei PFI aeey “oeacaoaey ooieoeee, aica?auathuae cia/a-

iea oeia INT”, eioi?ue caoai iiaeii auei au eniieueciaaoue a

i?ia?aiia ni?oe?iaee ec aeaau 5 a eiioaenoa aeaea

PFI STRCMP, NUMCMP, SWAP;

Eiathony aeaa iniiaiua i?e/eiu i?eiaiaiey iienaiee

TYPEDEF. Ia?aay i?e/eia naycaia n ia?aiao?ecaoeeae i?ia?aiiu,

/oiau iaeaa/eoue ?aoaiea i?iaeaiu ia?aiineiinoe. Anee aeey oe-

iia aeaiiuo, eioi?ua iiaoo auoue iaoeiii-caaeneiuie, eniieueci-

aaoue iienaiea TYPEDEF, oi i?e ia?aiina i?ia?aiiu ia ae?oaoth

iaoeio i?eaeaony eciaieoue oieueei yoe iienaiey. Iaeia ec oeie/-

iuo neooaoeee ninoieo a eniieueciaaiee ii?aaeaeyaiuo n iiiiuueth

TYPEDEF eiai aeey ?acee/iuo oeaeuo aaee/ei e a iineaaeothuai

iiaeoiaeyuai auai?a oeiia SHORT, INT e LONG aeey eaaeaeie eiath-

uaeny iaoeiu.

Aoi?ia iacia/aiea TYPEDEF ninoieo a iaania/aiee eo/oae aeieo-

iaioaoeee aeey i?ia?aiiu – oei n eiaiai TREEPTR iiaeao ieacaoue-

ny aieaa oaeiaiui aeey aini?eyoey, /ai oei, eioi?ue iienai

oieueei eae oeacaoaeue neiaeiie no?oeoo?u.

E iaeiiaoe, anaaaea nouanoaoao aa?iyoiinoue, /oi a aoaeouai eii-

ieeyoi? eee iaeioi?ay ae?oaay i?ia?aiia, oaeay eae LINT, nii-

aeao eniieueciaaoue niaea?aeauothny a iienaieyo TYPEDEF eioi?iaoeeth

aeey i?iaaaeaiey iaeioi?ie aeiiieieoaeueiie i?iaa?ee i?ia?aiiu.

· 152 –

7. Aaiae e auaiae

N?aaenoaa aaiaea/auaiaea ia yaeythony ninoaaiie /anoueth ycuea

“n”, oae /oi iu ia auaeaeyee eo a iaoai i?aaeuaeouai eceiaeaiee.

Iaeiaei ?aaeueiua i?ia?aiiu acaeiiaeaenoaotho ni naiae ie?oaeath-

uae n?aaeie ai?acaei aieaa neiaeiui ia?acii, /ai iu aeaeaee aei

neo ii?. A yoie aeaaa aoaeao iienaia “noaiaea?oiay aeaeeioaea

aaiaea/auaiaea”, oi anoue iaai? ooieoeee, ?ac?aaioaiiuo aeey

iaania/aiey noaiaea?oiie nenoaiu aaiaea/auaiaea aeey “n”- i?ia-

?aii. Yoe ooieoeee i?aaeiacia/aiu aeey oaeianoaa i?ia?aiiiiai

eioa?oaena, e ana aea io?aaeatho oieueei oa iia?aoeee, eioi?ua

iiaoo auoue iaania/aiu ia aieueoeinoaa nia?aiaiiuo iia?aoeeii-

iuo nenoai. I?ioeaaeo?u aeinoaoi/ii yooaeoeaiu aeey oiai, /oiau

iieueciaaoaee ?aaeei /oanoaiaaee iaiaoiaeeiinoue iaieoe eo “?aaee

yooaeoeaiinoe”, eae au ie auea aaaeia eiie?aoiay caaea/a. E,

iaeiiaoe, yoe i?ioeaaeo?u caaeoiaiu auoue “ia?aiineiuie” a oii

niunea, /oi iie aeieaeiu nouanoaiaaoue a niaianoeiii aeaea ia

ethaie nenoaia, aaea eiaaony ycue “n”, e /oi i?ia?aiiu, eioi-

?ua ia?aie/eaatho naie acaeiiaeaenoaey n nenoaiie aiciiaeiinoy-

ie, i?aaeinoaaeyaiuie noaiaea?oiie aeaeeioaeie, iiaeii aoaeao

ia?aiineoue n iaeiie nenoaiu ia ae?oaoth ii nouanoao aac eciaia-

iee.

Iu caeanue ia aoaeai iuoaoueny iienaoue anth aeaeeioaeo aai-

aea/auaiaea; iu aieaa caeioa?aniaaiu a oii, /oiau i?iaeaiiino-

?e?iaaoue nouiinoue iaienaiey “n”-i?ia?aii, eioi?ua acaeiiaeae-

noaotho ni naiae iia?aoeeiiiie n?aaeie.

7.1. Ia?auaiea e noaiaea?oiie aeaeeioaea

Eaaeaeue enoiaeiue oaee, eioi?ue ia?auaaony e ooieoeee ec

noaiaea?oiie aeaeeioaee, aeieaeai aaeece ia/aea niaea?aeaoue no?i-

eo

#INCLUDE

a oaeea STDIO.H ii?aaeaeythony iaeioi?ua iae?inu e ia?aiaiiua,

eniieuecoaiua aeaeeioaeie aaiaea/auaiaea. Eniieueciaaiea oaeiauo

neiaie aianoi iau/iuo aeaieiuo eaau/ae – oeacaiea eiiieeyoi?o

eneaoue yoio oaee a ni?aai/ieea, niaea?aeauai caaieiaee noai-

aea?oiie eioi?iaoeee (ia nenoaia UNIX iau/ii LUSRLINELUDE).

E?iia oiai, i?e caa?ocea i?ia?aiiu iiaeao ieacaoueny iaia-

oiaeeiui oeacaoue aeaeeioaeo yaii; ia nenoaia PDP-11 UNIX,

iai?eia?, eiiaiaea eiiieeyoeee i?ia?aiiu eiaea au aeae:

CC enoiaeiua oaeeu e o.ae. -LS

aaea -LS oeacuaaao ia caa?oceo ec noaiaea?oiie aeaeeioaee.

7.2. Noaiaea?oiue aaiae e auaiae – ooieoeee GETCHAR e

PUTCHAR

Naiue i?inoie iaoaieci aaiaea caeeth/aaony a /oaiee ii iae-

iiio neiaieo ca ?ac ec “noaiaea?oiiai aaiaea”, iau/ii n oa?ie-

iaea iieueciaaoaey, n iiiiuueth ooieoeee GETCHAR. Ooieoeey

GETCHAR() i?e eaaeaeii e iae ia?auaiee aica?auaao neaaeothuee

· 153 –

aaiaeeiue neiaie. A aieueoeinoaa n?aae, eioi?ua iiaeaea?aeeaatho

ycue “n”, oa?ieiae iiaeao auoue caiaiai iaeioi?ui oaeeii n ii-

iiuueth iaicia/aiey : anee PROG eniieuecoao PUTCHAR,

oi eiiaiaeiay no?iea

PROG>OUTFILE

i?eaaaeao e caiene noaiaea?oiiai auaiaea a oaee OUTFILE, a ia

ia oa?ieiae. Ia nenoaia UNIX iiaeii oaeaea eniieueciaaoue iioi/-

iue iaoaieci. No?iea

PROG ! ANOTHERPROG

iiiauaao noaiaea?oiue auaiae PROG a noaiaea?oiue aaiae ANOTHERPROG. E
iiyoue PROG ia aoaeao inaaaeiieaia ia eciaiaiee iai?aaeaiey.

Auaiae, inouanoaeyaiue ooieoeeae PRINTF, oaeaea iinooiaao a

noaiaea?oiue auaiae, e ia?auaiey e PUTCHAR e PRINTF iiaoo ia-

?aiaaeaoueny.

Ii?aceoaeueiia eiee/anoai i?ia?aii /eoaao oieueei ec iaeii-

ai aoiaeiiai iioiea e ieoao oieueei a iaeei auoiaeiie iioie; aeey

oaeeo i?ia?aii aaiae e auaiae n iiiiuueth ooieoeee GETCHAR,

PUTCHAR e PRINTF iiaeao ieacaoueny aiieia aaeaeaaoiui e aeey ia-

/aea ii?aaeaeaiii aeinoaoi/iui. Yoi iniaaiii ni?aaaaeeeai oia-

· 154 –

aea, eiaaea eiaaony aiciiaeiinoue oeacaiey oaeeia aeey aaiaea e

auaiaea e iioi/iue iaoaieci aeey nayce auaiaea iaeiie i?ia?aiiu

n aaiaeii ae?oaie. ?anniio?ei, iai?eia?, i?ia?aiio LOWER, ei-

oi?ay i?aia?acoao i?iieniua aoeau ec naiaai aaiaea a no?i/-

iua:

#INCLUDE

MAIN() /* CONVERT INPUT TO LOWER CASE */

(

INT C;

WHILE ((C = GETCHAR()) != EOF)

PUTCHAR(ISUPPER© ? TOLOWER© : C);

)

“Ooieoeee” ISUPPER e TOLOWER ia naiii aeaea yaeythony iae?ina-

ie, ii?aaeaeaiiuie a STDIO.H . Iae?in ISUPPER i?iaa?yao, ya-

eyaony ee aai a?aoiaio aoeaie ec aa?oiaai ?aaeno?a, e aica-

?auaao iaioeaaia cia/aiea, anee yoi oae, e ioeue a i?ioeaiii

neo/aa. Iae?in TOLOWER i?aia?acoao aoeao ec aa?oiaai ?aaeno-

?a a oo aea aoeao ieaeiaai ?aaeno?a. Iacaaeneii io oiai, eae

yoe ooieoeee ?aaeeciaaiu ia eiie?aoiie iaoeia, eo aiaoiaa ii-

aaaeaiea niaa?oaiii iaeeiaeiai, oae /oi eniieuecothuea eo i?ia-

?aiiu ecaaaeaiu io ciaiey neiaieueiiai iaai?a.

Anee o?aaoaony i?aia?aciaaoue ianeieueei oaeeia, oi iiaeii

nia?aoue yoe oaeeu n iiiiuueth i?ia?aiiu, iiaeiaiie ooeeeoa CAT

nenoaiu UNIX,

CAT FILE1 FILE2 … ! LOWER>OUTPUT

e ecaaaeaoue oai naiui aii?ina i oii, eae ia?aoeoueny e yoei

oaeeai ec i?ia?aiiu. (I?ia?aiia CAT i?eaiaeeony iicaea a yoie

aeaaa).

E?iia oiai ioiaoei, /oi a noaiaea?oiie aeaeeioaea aai-

aea/auaiaea “ooieoeee” GETCHAR e PUTCHAR ia naiii aeaea iiaoo

auoue iae?inaie. Yoi iicaieyao ecaaaeaoue iaeeaaeiuo ?anoiaeia ia

ia?auaiea e ooieoeee aeey ia?aaioee eaaeaeiai neiaiea. A aeaaa 8

iu i?iaeaiiino?e?oai, eae yoi aeaeaaony.

7.3. Oi?iaoiue auaiae – ooieoeey PRINTF

Aeaa ooieoeee: PRINTF aeey auaiaea e SCANF aeey aaiaea (neaaeo-

thuee ?acaeae) iicaieytho i?aia?aciauaaoue /eneaiiua aaee/eiu a

neiaieueiia i?aaenoaaeEiea e ia?aoii. Iie oaeaea iicaieytho aa-

ia?e?iaaoue e eioa?i?aoe?iaaoue oi?iaoiua no?iee. Iu oaea anthaeo

a i?aaeuaeoueo aeaaao iaoi?iaeueii eniieueciaaee ooieoeeth PRINTF;

caeanue i?eaiaeeony aieaa iieiia e oi/iia iienaiea. Ooieoeey

PRINTF(CONTROL, ARG1, ARG2, …)

· 155 –

i?aia?acoao, ii?aaeaeyao oi?iao e ia/aoaao naie a?aoiaiou a

noaiaea?oiue auaiae iiae oi?aaeaieai no?iee CONTROL. Oi?aaeyth-

uay no?iea niaea?aeeo aeaa oeia iauaeoia: iau/iua neiaieu, ei-

oi?ua i?inoi eiie?othony a auoiaeiie iioie, e niaoeeoeeaoeee

i?aia?aciaaiee, eaaeaeay ec eioi?uo aucuaaao i?aia?aciaaiea e

ia/aoue i/a?aaeiiai a?aoiaioa PRINTF.

Eaaeaeay niaoeeoeeaoeey i?aia?aciaaiey ia/eiaaony n neiaiea

% e caeai/eaaaony neiaieii i?aia?aciaaiey. Iaaeaeo % e neiai-

eii i?aia?aciaaiey iiaoo iaoiaeeoueny:

· ciae ieion, eioi?ue oeacuaaao i au?aaieaaiee i?aia?aciaai-

iiai a?aoiaioa ii eaaiio e?ath aai iiey.

· No?iea oeeo?, caaeathuay ieieiaeueioth oe?eio iiey. I?aia?aci-

aaiiia /enei aoaeao iaia/aoaii a iiea ii e?aeiae ia?a yoie

oe?eiu, a anee iaiaoiaeeii, oi e a aieaa oe?ieii. Anee i?a-

ia?aciaaiiue a?aoiaio eiaao iaiueoa neiaieia, /ai oeacaiiay

oe?eia iiey, oi ii aoaeao aeiiieiai neaaa (eee ni?aaa, anee

auei oeacaii au?aaieaaiea ii eaaiio e?ath)caiieiythueie nei-

aieaie aei yoie oe?eiu. Caiieiythuei neiaieii iau/ii yaeyao-

ny i?iaae, a anee oe?eia iiey oeacuaaaony n eeaee?othuei io-

eai, oi yoei neiaieii aoaeao ioeue (eeaee?othuee ioeue a aeaiiii

neo/aa ia icia/aao ainueia?e/iie oe?eiu iiey).

· Oi/ea, eioi?ay ioaeaeyao oe?eio iiey io neaaeothuae no?iee

oeeo?.

· No?iea oeeo? (oi/iinoue), eioi?ay oeacuaaao iaeneiaeueiia

/enei neiaieia no?iee, eioi?ua aeieaeiu auoue iaia/aoaiu, eee

/enei ia/aoaaiuo ni?aaa io aeanyoe/iie oi/ee oeeo? aeey ia?a-

iaiiuo oeia FLOAT eee DOUBLE.

· Iiaeeoeeaoi? aeeeiu L, eioi?ue oeacuaaao, /oi niioaaonoaoth-

uee yeaiaio aeaiiuo eiaao oei LONG, a ia INT.

Ieaea i?eaiaeyony neiaieu i?aia?aciaaiey e eo niune:

D – a?aoiaio i?aia?acoaony e aeanyoe/iiio aeaeo.

O – A?aoiaio i?aia?acoaony a aacciaeiaoth ainueia?e/ioth oi?io

(aac eeaee?othuaai ioey).

X – A?aoiaio i?aia?acoaony a aacciaeiaoth oanoiaaeoeaoa?e/ioth

oi?io (aac eeaee?othueo 0X).

U – A?aoiaio i?aia?acoaony a aacciaeiaoth aeanyoe/ioth oi?io.

C – A?aoiaio ?anniao?eaaaony eae ioaeaeueiue neiaie.

S – A?aoiaio yaeyaony no?ieie: neiaieu no?iee ia/aoathony aei

oao ii?, iiea ia aoaeao aeinoeaioo ioeaaie neiaie eee ia ao-

aeao iaia/aoaii eiee/anoai neiaieia, oeacaiiia a niaoeeoeea-

oeee oi/iinoe.

E – A?aoiaio, ?anniao?eaaaiue eae ia?aiaiiay oeia FLOAT eee

DOUBLE, i?aia?acoaony a aeanyoe/ioth oi?io a aeaea

[-]M.NNNNNNE[+-]XX, aaea aeeeia no?iee ec N ii?aaeaeyaony

oeacaiiie oi/iinoueth. Oi/iinoue ii oiie/aieth ?aaia 6.

F – A?aoiaio, ?anniao?eaaaiue eae ia?aiaiiay oeia FLOAT eee

DOUBLE, i?aia?acoaony a aeanyoe/ioth oi?io a aeaea

[-]MMM.NNNNN, aaea aeeeia no?iee ec N ii?aaeaeyaony oeacaiiie

oi/iinoueth. Oi/iinoue ii oiie/aieth ?aaia 6. ioiaoei, /oi yoa

oi/iinoue ia ii?aaeaeyao eiee/anoai ia/aoaaiuo a oi?iaoa F

cia/aueo oeeo?.

· 156 –

G – Eniieuecoaony eee oi?iao %E eee %F, eaeie ei?i/a; iacia-

/auea ioee ia ia/aoathony.

Anee eaeouee ca % neiaie ia yaeyaony neiaieii i?aia?aciaaiey,

oi ia/aoaaony nai yoio neiaie; neaaeiaaoaeueii,neiaie % iiaeii

iaia/aoaoue, oeacaa %%.

Aieueoeinoai ec oi?iaoiuo i?aia?aciaaiee i/aaeaeii e auei

i?ieeethno?e?iaaii a i?aaeuaeoueo aeaaao. Aaeeinoaaiiui eneeth/a-

ieai yaeyaony oi, eae oi/iinoue acaeiiaeaenoaoao ni no?ieaie.

Neaaeothuay oaaeeoea aeaiiino?e?oao aeeyiea caaeaiey ?acee/iuo

niaoeeoeeaoeee ia ia/aoue “HELLO, WORLD” (12 neiaieia). Iu ii-

ianoeee aeaiaoi/ey aie?oa eaaeaeiai iiey aeey oiai, /oiau au

iiaee aeaeaoue aai i?ioyaeaiiinoue.

:%10S: :HELLO, WORLD:

:%10-S: :HELLO, WORLD:

:%20S: : HELLO, WORLD:

:%-20S: :HELLO, WORLD :

:%20.10S: : HELLO, WOR:

:%-20.10S: :HELLO, WOR :

:%.10S: :HELLO, WOR:

I?aaeinoa?aaeaiea: PRINTF eniieuecoao naie ia?aue a?aoiaio

aeey ii?aaeaeaiey /enea iineaaeothueo a?aoiaioia e eo oeiia. An-

ee eiee/anoai a?aoiaioia ieaaeaony iaaeinoaoi/iui eee iie ao-

aeoo eiaoue ianiioaaonoaaiiua oeiu, oi aicieeiao iooaieoea e au

iieo/eoa aanniuneaiiua ?acoeueoaou.

Oi?aaeiaiea 7-1.

Iaieoeoa i?ia?aiio, eioi?ay aoaeao ia/aoaoue ?acoiiui ia-

?acii i?iecaieueiue aaiae. Eae ieieioi iia aeieaeia ia/aoaoue

iaa?aoe/aneea neiaieu a ainueia?e/iii eee oanoiaaeoeaoa?e/iii

aeaea (a niioaaonoaee n i?eiyouie o aan iau/ayie) e neeaaeu-

aaoue aeeeiiua no?iee.

7.4. Oi?iaoiue aaiae – ooieoeey SCANF

Inouanoaeythuay aaiae ooieoeey SCANF yaeyaony aiaeiaii

PRINTF e iicaieyao i?iaiaeeoue a ia?aoiii iai?aaeaiee iiiaea

ec oao aea naiuo i?aia?aciaaiee. Ooieoeey

SCANF(CONTROL, ARG1, ARG2, …)

/eoaao neiaieu ec noaiaea?oiiai aaiaea, eioa?i?aoe?oao eo a

niioaaonoaee n oi?iaoii, oeacaiiii a a?aoiaioa CONTROL, e

iiiauaao ?acoeueoaou a inoaeueiua a?aoiaiou. Oi?aaeythuee a?ao-

iaio iienuaaaony ieaea; ae?oaea a?aoiaiou, eaaeaeue ec eioi?uo

aeieaeai auoue oeacaoaeai, ii?aaeaeytho, eoaea neaaeoao iiianoeoue

niioaaonoaothuei ia?acii i?aia?aciaaiiue aaiae.

Oi?aaeythuay no?iea iau/ii niaea?aeeo niaoeeoeeaoeee i?aia?a-

ciaaiey, eioi?ua eniieuecothony aeey iaiin?aaenoaaiiie eioa?i?a-

oaoeee aoiaeiuo iineaaeiaaoaeueiinoae. Oi?aaeythuay no?iea iiaeao

niaea?aeaoue:

· i?iaaeu, oaaoeyoeee eee neiaieu iiaie no?iee (“neiaieu ion-

ouo i?iiaaeooeia”), eioi?ua eaii?e?othony.

· 157 –

· Iau/iua neiaieu (ia %), eioi?ua i?aaeiieaaathony niaiaaeathue-

ie ni neaaeothueie ioee/iuie io neiaieia ionouo i?iiaaeooeia

neiaieaie aoiaeiiai iioiea.

· Niaoeeoeeaoeee i?aia?aciaaiey, ninoiyuea ec neiaiea %, iai-

aycaoaeueiiai neiaiea iiaeaaeaiey i?enaaeaaiey *, iaiayca-

oaeueiiai /enea, caaeathuaai iaeneiaeueioth oe?eio iiey e nei-

aiea i?aia?aciaaiey.

Niaoeeoeeaoeey i?aia?aciaaiey oi?aaeyao i?aia?aciaaieai

neaaeothuaai iiey aaiaea. ii?iaeueii ?acoeueoao iiiauaaony a ia-

?aiaiioth, eioi?ay oeacuaaaony niioaaonoaothuei a?aoiaioii.

Anee, iaeiaei , n iiiiuueth neiaiea * oeacaii iiaeaaeaiea i?en-

aaeaaiey, oi yoi iiea aaiaea i?inoi i?iioneaaony e ieeaeiai

i?enaaeaaiey ia i?iecaiaeeony. Iiea aaiaea ii?aaeaeyaony eae

no?iea neiaieia, eioi?ua ioee/iu io neiaieia i?inouo i?iia-

aeooeia; iii i?iaeieaeaaony eeai aei neaaeothuaai neiaiea ionoiai

i?iiaaeooea, eeai iiea ia aoaeao en/a?iaia oe?eia iiey, anee

iia oeacaia. Ionthaea neaaeoao, /oi i?e iienea ioaeiiai ae aai-

aea, ooieoeey SCANF aoaeao ia?anaeaoue a?aieoeu no?ie, iineieueeo

neiaie iiaie no?iee aoiaeeo a /enei ionouo i?iiaaeooeia.

Neiaie i?aia?aciaaiey ii?aaeaeyao eioa?i?aoaoeeth iiey aai-

aea; niaeanii o?aaiaaieyi iniiaaiiie ia auciaa ii cia/aieth

naiaioeee ycuea “n” niioaaonoaothuee a?aoiaio aeieaeai auoue

oeacaoaeai. Aeiioneathony neaaeothuea neiaieu i?aia?aciaaiey:

D – ia aaiaea iaeeaeaaony aeanyoe/iia oeaeia; niioaaonoaothuee a?-

aoiaio aeieaeai auoue oeacaoaeai ia oeaeia.

O – Ia aaiaea iaeeaeaaony ainueia?e/iia oeaeia (n eeaee?othuei io-

eai eee aac iaai); niioaaonoaothuee a?aoiaio aeieaeai auoue

oeacaoaeai ia oeaeia.

X – Ia aaiaea iaeeaeaaony oanoiaaeoeaoa?e/iia oeaeia (n eeaee?othue-

ie 0X eee aac ieo); niioaaonoaothuee a?aoiaio aeieaeai auoue

oeacaoaeai ia oeaeia.

H – Ia aaiaea iaeeaeaaony oeaeia oeia SHORT; niioaaonaothuee a?-

aoiaio aeieaeai auoue oeacaoaeai ia oeaeia oeia SHORT.

C – Iaeeaeaaony ioaeaeueiue neiaie; niioaaonoaothuee a?aoiaio

aeieaeai auoue oeacaoaeai ia neiaieu; neaaeothuee aaiaeeiue

neiaie iiiauaaony a oeacaiiia ianoi. Iau/iue i?iione nei-

aieia ionouo i?iiaaeooeia a yoii neo/aa iiaeaaeyaony; aeey

/oaiey neaaeothuaai neiaiea, eioi?ue ia yaeyaony neiaieii

ionoiai i?iiaaeooea, iieuecoeoanue niaoeeoeeaoeeae i?aia?aci-

aaiey %1S.

S – Iaeeaeaaony neiaieueiay no?iea; niioaaonoaothuee a?aoiaio

aeieaeai auoue oeacaoaeai neiaieia, eioi?ue oeacuaaao ia

iannea neiaieia, eioi?ue aeinoaoi/ii aaeee aeey i?eiyoey

no?iee e aeiaaaeyaiiai a eiioea neiaiea 0.

F – Iaeeaeaaony /enei n ieaaathuae oi/eie; niioaaonoaothuee a?-

aoiaio aeieaeai auoue oeacaoaeai ia ia?aiaiioth oeia FLOAT.

A – neiaie i?aia?aciaaiey E yaeyaony neiiieiii aeey F. Oi?iao

aaiaea ia?aiaiiie oeia FLOAT aeeth/aao iaiaycaoaeueiue ciae,

no?ieo oeeo?, aiciiaeii niaea?aeauoth aeanyoe/ioth oi/eo e iai-

aycaoaeueiia iiea yeniiiaiou, ninoiyuaa ec aoeau E, ca ei-

oi?ie neaaeoao oeaeia, aiciiaeii eiathuaa ciae.

· 158 –

Ia?aae neiaieaie i?aia?aciaaiey D, O e X iiaeao noiyoue L,

eioi?ay icia/aao , /oi a nienea a?aoiaioia aeieaeai iaoiaeeoueny

oeacaoaeue ia ia?aiaiioth oeia LONG, a ia oeia INT. Aiaeiae/-

ii, aoeaa L iiaeao noiyoue ia?aae neiaieaie i?aia?aciaaiey E

eee F, aiai?y i oii, /oi a nienea a?aoiaioia aeieaeai iaoi-

aeeoueny oeacaoaeue ia ia?aiaiioth oeia DOUBLE, a ia oeia FLOAT.

Iai?eia?, ia?auaiea

INT I;

FLOAT X;

CHAR NAME[50];

SCANF(“&D %F %S”, &I, &X, NAME);

ni no?ieie ia aaiaea

25 54.32E-1 THOMPSON

i?eaiaeeo e i?enaaeaaieth I cia/aiey 25,X – cia/aiey 5.432 e

NAME – no?iee “THOMPSON”, iaaeeaaeauei ia?acii caeii/aiiie

neiaieii 0. yoe o?e iiey aaiaea iiaeii ?acaeaeeoue noieueeeie

i?iaaeaie, oaaoeyoeeyie e neiaieaie iiauo no?ie, neieueei au

iiaeaeaaoa. Ia?auaiea

INT I;

FLOAT X;

CHAR NAME[50];

SCANF(“%2D %F %*D %2S”, &I, &X, NAME);

n aaiaeii

56789 0123 45A72

i?enaieo I cia/aiea 56, X – 789.0, i?iionoeo 0123 e iiianoeo

a NAME no?ieo “45”. i?e neaaeothuai ia?auaiee e ethaie i?ioeaaeo-

?a aaiaea ?anniio?aiea ia/iaony n aoeau A. A yoeo aeaoo i?eia-

?ao NAME yaeyaony oeacaoaeai e, neaaeiaaoaeueii, ia?aae iei ia

ioaeii iiiauaoue ciae &.

A ea/anoaa ae?oaiai i?eia?a ia?aieoai oaia?ue yeaiaioa?iue

eaeueeoeyoi? ec aeaau 4, eniieuecoy aeey i?aia?aciaaiey aaiaea

ooieoeeth SCANF:

#INCLUDE

MAIN() /* RUDIMENTARY DESK CALCULATOR */

(

DOUBLE SUM, V;

SUM =0;

WHILE (SCANF(“%LF”, &V) !=EOF)

PRINTF(“T%.2FN”, SUM += V);

)

auiieiaiea ooieoeee SCANF caeai/eaaaony eeai oiaaea, eiaaea iia

en/a?iuaaao naith oi?aaeythuoth no?ieo, eeai eiaaea iaeioi?ue

yeaiaio aaiaea ia niaiaaeaao n oi?aaeythuae niaoeeoeeaoeeae. A

ea/anoaa naiaai cia/aiey iia aica?auaao /enei i?aaeeueii nia-

iaaeathueo e i?enaiaiiuo yeaiaioia aaiaea. Yoi /enei iiaeao auoue

· 159 –

eniieueciaaii aeey ii?aaeaeaiey eiee/anoaa iaeaeaiiuo yeaiaioia

aaiaea. i?e auoiaea ia eiiaoe oaeea aica?auaaony EOF; iiae/a?e-

iai, /oi yoi cia/aiea ioee/ii io 0, /oi neaaeothuee aaiaeeiue

neiaie ia oaeiaeaoai?yao ia?aie niaoeeoeeaoeee a oi?aaeythuae

no?iea. I?e neaaeothuai ia?auaiee e SCANF iiene aiciaiiaeyaony

iaiin?aaenoaaiii ca iineaaeiei aaaaeaiiui neiaieii.

Caeeth/eoaeueiia i?aaeinoa?aaeaiea: a?aoiaiou ooieoeee SCANF

aeieaeiu auoue oeacaoaeyie. Ianiiiaiii iaeaieaa ?ani?ino?aiai-

iay ioeaea ninoieo a iaienaiee

SCANF(“%D”, N);

aianoi

SCANF(“%D”, &N);

7.5. Oi?iaoiia i?aia?aciaaiea a iaiyoe

Io ooieoeee SCANF e PRINTF i?ienoiaeyo ooieoeee SSCANF e

SPRINTF, eioi?ua inouanoaeytho aiaeiae/iua i?aia?aciaaiey, ii

iia?e?otho ni no?ieie, a ia n oaeeii. Ia?auaiey e yoei ooie-

oeeyi eiatho aeae:

SPRINTF(STRING, CONTROL, ARG1, ARG2, …)

SSCANF(STRING, CONTROL, ARG1, ARG2, …)

Eae e ?aiueoa , ooieoeey SPRINTF i?aia?acoao naie a?aoiaiou

ARG1, ARG2 e o.ae. A niioaaonoaee n oi?iaoii, oeacaiiui a

CONTROL, ii iiiauaao ?acoeueoaou a STRING, a ia a noaiaea?oiue

auaiae. KIia/ii, no?iea STRING aeieaeia auoue aeinoaoi/ii aaeeea,

/oiau i?eiyoue ?acoeueoao. Iai?eia?, anee NAME – yoi neiaieue-

iue iannea, a N – oeaeia, oi

SPRINTF(NAME, “TEMP%D”, N);

nicaeaao a NAME no?ieo aeaea TEMPNNN, aaea NNN – cia/aiea N.

Ooieoeey SSCANF auiieiyao ia?aoiua i?aia?aciaaiey – iia

i?iniao?eaaao no?ieo STRING a niioaaonoaee n oi?iaoii a a?-

aoiaioa CONTROL e iiiauaao ?acoeueoe?othuea cia/aiey a a?ao-

iaiou ARG1, ARG2 e o.ae.yoe a?aoiaiou aeieaeiu auoue oeacaoaey-

ie. A ?acoeueoaoa ia?auaiey

SSCANF(NAME, “TEMP%D”, &N);

ia?aiaiiay N iieo/aao cia/aiea no?iee oeeo?, neaaeothueo ca

TEMP a NAME.

Oi?aaeiaiea 7-2.

Ia?aieoeoa ianoieueiue eaeueeoeyoi? ec aeaau 4, eniieuecoy

aeey aaiaea e i?aia?aciaaiey /enae SCANF e/eee SSCANF.

· 160 –

7.6. Aeinooi e oaeeai

Ana aei neo ii? iaienaiiua i?ia?aiiu /eoaee ec noaiaea?o-

iiai aaiaea e ienaee a noaiaea?oiue auaiae, ioiineoaeueii eioi-

?uo iu i?aaeiieaaaee, /oi iie iaae/aneei ia?acii i?aaeinoaaea-

iu i?ia?aiia ianoiie iia?aoeeiiiie nenoaiie.

Neaaeothuei oaaii a aii?ina aaiaea-auaiaea yaeyaony iaiena-

iea i?ia?aiiu, ?aaioathuae n oaeeii, eioi?ue ia naycai ca?a-

iaa n i?ia?aiiie. iaeiie ec i?ia?aii, eioi?ay yaii aeaiiino?e-

?oao iio?aaiinoue a oaeeo iia?aoeeyo, yaeyaony CAT, eioi?ay

iauaaeeiyao iaai? ec ianeieueeeo eiaiiaaiiuo oaeeia a noaiaea?-

oiue auaiae. I?ia?aiia CAT eniieuecoaony aeey auaiaea oaeeia ia

oa?ieiae e a ea/anoaa oieaa?naeueiiai nai?ueea aaiaea aeey

i?ia?aii, eioi?ua ia eiatho aiciiaeiinoe ia?auaoueny e oaeeai

ii eiaie. Iai?eia?, eiiaiaea

CAT X.C.Y.C

ia/aoaao niaea?aeeiia oaeeia X.C e Y.C a noaiaea?oiue auaiae.

Aii?in ninoieo a oii, eae i?aaieciaaoue /oaiea ec eiaii-

aaiiuo oaeeia, o.a., eae naycaoue aiaoiea eiaia, eioi?uie

iuneeo iieueciaaoaeue, n oaeoe/anee /eoathueie aeaiiua iia?aoi-

?aie.

Yoe i?aaeea i?inou. I?aaeaea /ai iiaeii n/eouaaoue ec iaei-

oi?iai oaeea eee caienuaaoue a iaai, yoio oaee aeieaeai auoue

ioe?uo n iiiiuueth ooieoeee FOPEN ec noaiaea?oiie aeaeeioaee.

ooieoeey FOPEN aa?ao aiaoiaa eiy (iiaeiaiia X.C eee Y.C), i?i-

aiaeeo iaeioi?ua ianeoaeeaathuea aeaenoaey e ia?aaiai?u n iia?a-

oeeiiiie nenoaiie (aeaoaee eioi?uo ia aeieaeiu ian eanaoueny) e

aica?auaao aioo?aiiaa eiy, eioi?ia aeieaeii eniieueciaaoueny i?e

iineaaeothueo /oaieyo ec oaeea eee caienyo a iaai.

Yoi aioo?aiiaa eiy, iacuaaaiia “oeacaoaeai oaeea”, oae-

oe/anee yaeyaony oeacaoaeai no?oeoo?u, eioi?ay niaea?aeeo ei-

oi?iaoeeth i oaeea, oaeoth eae ianoi ?aciauaiey aooa?a, oaeouay

iiceoeey neiaiea a aooa?a, i?ienoiaeeo ee /oaiea ec oaeea eee

caienue a iaai e oiio iiaeiaiia. Iieueciaaoaee ia iaycaiu ciaoue

yoe aeaoaee, iioiio /oi n?aaee ii?aaeaeaiee aeey noaiaea?oiiai

aaiaea-auaiaea, iieo/aaiuo ec oaeea STDIO.H, niaea?aeeony ii?a-

aeaeaiea no?oeoo?u n eiaiai FILE. Aaeeinoaaiiia iaiaoiaeeiia

aeey oeacaoaey oaeea iienaiea aeaiiino?e?oaony i?eia?ii:

FILE *FOPEN(), *FP;

Caeanue aiai?eony, /oi FP yaeyaony oeacaoaeai ia FILE e

FOPEN aica?auaao oeacaoaeue ia FILE. Oa?aoeoa aieiaiea, /oi

FILE yaeyaony eiaiai oeia, iiaeiaiui INT, a ia y?eueo no?oe-

oo?u; yoi ?aaeeciaaii eae TYPEDEF. (Iiae?iaiinoe oiai, eae

ana yoi ?aaioaao ia nenoaia UNIX, i?eaaaeaiu a aeaaa 8).

Oaeoe/aneia ia?auaiea e ooieoeee FOPEN a i?ia?aiia eiaao

aeae:

FP=FOPEN(NAME,MODE);

· 161 –

Ia?aui a?aoiaioii ooieoeee FOPEN yaeyaony “eiy” oaeea, eioi-

?ia caaeaaony a aeaea neiaieueiie no?iee. Aoi?ie a?aoiaio MODE

(“?aaeei”) oaeaea yaeyaony neiaieueiie no?ieie, eioi?ay oeacu-

aaao, eae yoio oaee aoaeao eniieueciaaoueny. Aeiionoeiuie ?aaee-

iaie yaeythony: /oaiea (“R”), caienue (“W”) e aeiaaaeaiea

(“A”).

Anee au ioe?iaoa oaee, eioi?ue aua ia nouaoaoao, aeey ca-

iene eee aeiaaaeaiey, oi oaeie oaee aoaeao nicaeai (anee yoi

aiciiaeii). Ioe?uoea nouanoaothuaai oaeea ia caienue i?eaiaeeo e

ioa?anuaaieth aai noa?iai niaea?aeeiiai. Iiiuoea /oaiey iano-

uanoaothuaai oaeea yaeyaony iueaeie. Ioeaee iiaoo auoue iaon-

eiaeaiu e ae?oaeie i?e/eiaie (iai?eia?, iiiuoeie /oaiey ec

oaeea, ia eiay ia oi ?ac?aoaiey). I?e iaee/ee eaeie-eeai

ioeaee ooieoeey aica?auaao ioeaaia cia/aiea oeacaoaey NULL

(eioi?ia aeey oaeianoaa oaeaea ii?aaeaeyaony a oaeea STDIO.H).

Ae?oaie iaiaoiaeeiie aauueth yaeyaony niinia /oaiey eee ca-

iene, anee oaee oaea ioe?uo. Caeanue eiaaony ianeieueei aiciiae-

iinoae, ec eioi?uo GETC e PUTC yaeythony i?inoaeoeie.ooieoeey

GETC aica?auaao neaaeothuee neiaie ec oaeea; ae iaiaoiaeei oea-

caoaeue oaeea, /oiau ciaoue, ec eaeiai oaeea /eoaoue. Oaeei ia-

?acii,

C=GETC(FP)

iiiauaao a “C” neaaeothuee neiaie ec oaeea, oeacaiiiai iin?aae-

noaii FP, e EOF, anee aeinoeaioo eiiaoe oaeea.

Ooieoeey PUTC, yaeythuayny ia?auaieai e ooieoeee GETC,

PUTC(C,FP)

iiiauaao neiaie “C” a oaee FP e aica?auaao “C”. Iiaeiaii ooi-eoeeyi
GETCHAR e PUTCHAR, GETC e PUTC iiaoo auoue iae?inaie, a ia ooieoeeyie.

I?e caionea i?ia?aiiu aaoiiaoe/anee ioe?uaathony o?e oae-

ea, eioi?ua niaaaeaiu ii?aaeaeaiiuie oeacaoaeyie oaeeia. Yoeie

oaeeaie yaeythony noaiaea?oiue aaiae, noaiaea?oiue auaiae e noai-

aea?oiue auaiae ioeaie; niioaaonoaothuea oeacaoaee oaeeia iacu-

aathony STDIN, STDOUT e STDERR. Iau/ii ana yoe oeacaoaee nay-

caiu n oa?ieiaeii, ii STDIN e STDOUT iiaoo auoue ia?aiai?aa-

eaiu ia oaeeu eee a iioie (PIPE), eae iienuaaeinue a ?acaeaea

7.2.

Ooieoeee GETCHAR e PUTCHAR iiaoo auoue ii?aaeaeaiu a oa?ie-

iaeao GETC, PUTC, STDIN e STDOUT neaaeothuei ia?acii:

#DEFINE GETCHAR() GETC(STDIN) #DEFINE PUTCHAR© PUTC(C,

STDOUT)

I?e ?aaioa n oaeeaie aeey oi?iaoiiai aaiaea e auaiaea iiaeii en-

iieueciaaoue ooieoeee FSCANF e FPRINTF. Iie eaeaioe/iu ooieoeeyi

SCANF e PRINTF, ca eneeth/aieai oiai, /oi ia?aui a?aoiaioii

yaeyaony oeacaoaeue oaeea, ii?aaeaeythuee oio oaee, eioi?ue ao-

aeao /eoaoueny eee eoaea aoaeao aanoenue caienue; oi?aaeythuay

no?iea aoaeao aoi?ui a?aoiaioii.

· 162 –

Iieii/ea n i?aaeaa?eoaeueiuie caia/aieyie, iu oaia?ue a

ninoiyiee iaienaoue i?ia?aiio CAT aeey eiieaoaiaoeee oaeeia.

Eniieuecoaiay caeanue iniiaiay noaia ieacuaaaony oaeiaiie ai

iiiaeo i?ia?aiiao: anee eiathony a?aoiaiou a eiiaiaeiie no?i-

ea, oi iie ia?aaaouaathony iineaaeiaaoaeueii. Anee oaeea a?ao-

iaiou ionoonoaotho, oi ia?aaaouaaaony noaiaea?oiue aaiae. Yoi

iicaieyao eniieueciaaoue i?ia?aiio eae naiinoiyoaeueii, oae e

eae /anoue aieueoae caaea/e.

#INCLUDE

MAIN(ARGC, ARGV) /*CAT: CONCATENATE FILES*/

INT ARGC;

CHAR *ARGV[];

(

FILE *FP, *FOPEN();

IF(ARGC==1) /*NO ARGS; COPY STANDARD INPUT*/

FILECOPY(STDIN);

ELSE

WHILE (–ARGC > 0)

IF ((FP=FOPEN(*++ARGV,”R”))==NULL) (

PRINTF(“CAT:CAN’T OPEN %N”,*ARGV);

BREAK;

) ELSE (

FILECOPY(FP);

FCLOSE(FP);

)

)

FILECOPY(FP) /*COPY FILE FP TO STANDARD OUTPUT*/

FILE *FP;

(

INT C;

WHILE ((C=GETC(FP)) !=EOF)

PUTC(C, STDOUT);

)

Oeacaoaee oaeeia STDIN e STDOUT ca?aiaa ii?aaeaeaiu a aeaeei-

oaea aaiaea-auaiaea eae noaiaea?oiue aaiae e noaiaea?oiue auaiae;

iie iiaoo auoue eniieueciaaiu a ethaii ianoa, aaea iiaeii eniieue-

ciaaoue iauaeo oeia FILE*.iie iaeiaei yaeythony eiinoaioaie, a

ia ia?aiaiiuie, oae /oi ia iuoaeoanue ei /oi-eeai i?enaae-

aaoue.

Ooieoeey FCLOSE yaeyaony ia?aoiie ii ioiioaieth e FOPEN;

iia ?ac?uaaao naycue iaaeaeo oeacaoaeai oaeea e aiaoiei eiaiai,

onoaiiaeaiioth ooieoeeae FOPEN, e aunaiaiaeaeaao oeacaoaeue oaeea

aeey ae?oaiai oaeea.aieueoeinoai iia?aoeeiiiuo nenoai eiatho ia-

eioi?ua ia?aie/aiey ia /enei iaeiia?aiaiii ioe?uouo oaeeia,

eioi?uie iiaeao ?anii?yaeaoueny i?ia?aiia. Iiyoiio, oi eae iu

iinooieee a CAT, inaiaiaeea ia ioaeiua iai aieaa iauaeou, ya-

eyaony oi?ioae eaeaae. Eiaaony e ae?oaay i?e/eia aeey i?eiaia-

iey ooieoeee FCLOSE e auoiaeiiio oaeeo – iia aucuaaao auaea/o

eioi?iaoeee ec aooa?a, a eioi?ii PUTC niae?aao auaiae. (I?e

ii?iaeueiii caaa?oaiee ?aaiou i?ia?aiiu ooieoeey FCLOSE aucu-

aaaony aaoiiaoe/anee aeey eaaeaeiai ioe?uoiai oaeea).

· 163 –

7.7. Ia?aaioea ioeaie – STDERR e EXIT

Ia?aaioea ioeaie a CAT iaeaeaaeueia. Iaoaeianoai caeeth/aao-

ny a oii, /oi anee iaeei ec oaeeia ii iaeioi?ie i?e/eia iea-

cuaaaony iaaeinooiiui, aeeaaiinoe/aneia niiauaiea ia yoii ia-

/aoaaony a eiioea iauaaeeiaiiiai auaiaea. Yoi i?eaieaii, anee

auaiae iinooiaao ia oa?ieiae, ii ia aiaeeony, anee auaiae iin-

ooiaao a iaeioi?ue oaee eee /a?ac iioi/iue (PIPELINE) iaoa-

ieci a ae?oaoth i?ia?aiio.

*oiau eo/oa ia?aaaouaaoue oaeoth neooaoeeth, e i?ia?aiia

oi/ii oaeei aea ia?acii, eae STDIN e STDOUT, i?eniaaeeiyaony

aoi?ie auoiaeiie oaee, iacuaaaiue STDERR. Anee yoi aiiaua

aiciiaeii, auaiae, caienaiiue a oaeea STDERR, iiyaeyaony ia

oa?ieiaea iieueciaaoaey, aeaaea anee noaiaea?oiue auaiae iai?aa-

eyaony a ae?oaia ianoi.

Aeaaaeoa ia?aaeaeaai i?ia?aiio CAT oaeei ia?acii, /oiau

niiauaiey ia ioeaeao ienaeenue a noaiaea?oiue oaee ioeaie.

“INCLUDE

MAIN(ARGC,ARGV) /*CAT: CONCATENATE FILES*/

INT ARGC;

CHAR *ARGV[];

(

FILE *FP, *FOPEN();

IF(ARGC==1) /*NO ARGS; COPY STANDARD INPUT*/

FILECOPY(STDIN);

ELSE

WHILE (–ARGC > 0)

IF((FP=FOPEN(*++ARGV,”R#))==NULL) (

PRINTF(STDERR,

“CAT: CAN’T OPEN,%SN”, ARGV);

EXIT(1);

) ELSE (

FILECOPY(FP);

)

EXIT(0);

)

I?ia?aiia niiauaao ia ioeaeao aeaoiy niiniaaie. Aeeaaiinoe/an-

eia niiauaiea, auaeaaaaiia ooieoeeae FPRINTF, iinooiaao a

STDERR e, oaeei ia?acii, ieacuaaaony ia oa?ieiaea iieueciaa-

oaey, a ia en/acaao a iioiea (PIPELINE) eee a auoiaeiii oae-

ea.

I?ia?aiia oaeaea eniieuecoao ooieoeeth EXIT ec noaiaea?oiie

aeaeeioaee, ia?auaiea e eioi?ie aucuaaao caaa?oaiea auiieia-

iey i?ia?aiiu. A?aoiaio ooieoeee EXIT aeinooiai ethaie i?ia?ai-

ia, ia?auathuaeny e aeaiiie ooieoeee, oae /oi oniaoiia eee iao-

aea/iia caaa?oaiea aeaiiie i?ia?aiiu iiaeao auoue i?iaa?aii ae?o-

aie i?ia?aiiie, eniieuecothuae yoo a ea/anoaa iiaecaaea/e. Ii

niaeaoaieth aaee/eia 0 a ea/aonaa aica?auaaiiai cia/aiey nae-

aeaoaeuenoaoao i oii, /oi ana a ii?yaeea, a ?acee/iua iaioeaaua

cia/aiey yaeythony i?eciaeaie ii?iaeueiuo neooaoeee.

· 164 –

Ooieoeey EXIT aucuaaao ooieoeeth FCLOSE aeey eaaeaeiai ioe?u-

oiai auoiaeiiai oaeea, n oai /oiau auaanoe anth iiiauaiioth a

aooa?u auoiaeioth eioi?iaoeeth, a caoai aucuaaao ooieoeeth _EXIT.

Ooieoeey _EXIT i?eaiaeeo e iaiaaeeaiiiio caaa?oaieth aac i/enoee

eaeeo-eeai aooa?ia; eiia/ii, i?e aeaeaiee e yoie ooieoeee iiae-

ii ia?aoeoueny iaiin?aaenoaaiii.

7.8. Aaiae e auaiae no?ie

Noaiaea?oiay aeaeeioaea niaea?aeeo ooieoeeth FGETS, niaa?oai-

ii aiaeiae/ioth ooieoeee GETLINE, eioi?oth iu eniieueciaaee ia

anai i?ioyaeaiee eieae. A ?acoeueoaoa ia?auaiey

FGETS(LINE, MAXLINE, FP)

neaaeothuay no?iea aaiaea (aeeth/ay neiaie iiaie no?iee) n/eou-

aaaony ec oaeea FP a neiaieueiue iannea LINE; naiia aieueoia

MAXLINE_1 neiaie aoaeao i?i/eoai. ?acoeueoe?othuay no?iea ca-

eai/eaaaony neiaieii 0. Ii?iaeueii ooieoeey FGETS aica?auaao

LINE; a eiioea oaeea iia aica?auaao NULL. (Iaoa ooieoeey

GETLINE aica?auaao aeeeio no?iee, a i?e auoiaea ia eiiaoe oaeea

· ioeue).

I?aaeiacia/aiiay aeey auaiaea ooieoeey FPUTS caienuaaao

no?ieo (eioi?ay ia iaycaia niaea?aeaoue neiaie iiaie no?iee) a

oaee:

FPUTS(LINE, FP)

*oiau iieacaoue, /oi a ooieoeeyo oeia FGETS e FPUTS iao ie/aai
oaeinoaaiiiai, iu i?eaiaeei eo ieaea, neiie?iaaiiuie iaiin?aaenoaaiii ec
noaiaea?oiie aeaeeioaee aaiaea-auaiaea:

#INCLUDE

CHAR *FGETS(S,N,IOP) /*GET AT MOST N CHARS FROM IOP*/

CHAR *S;

INT N;

REGISTER FILE *IOP;

(

REGISTER INT C;

REGISTER CHAR *CS;

CS = S;

WHILE(–N>0&&(C=GETC(IOP)) !=EOF)

IF ((*CS++ = C)==’N’)

BREAK;

*CS = ‘0’;

RETURN((C==EOF && CS==S) 7 NULL : S);

)

FPUTS(S,IOP) /*PUT STRING S ON FILS IOP*/

REGISTER CHAR *S;

REGISTER FILE *IOP;

(

REGISTER INT C;

WHILE (C = *S++)

PUTC(C,IOP);

)

· 165 –

Oi?aaeiaiea 7-3.

Iaieoeoa i?ia?aiio n?aaiaiey aeaoo oaeeia, eioi?ay aoaeao

ia/aoaoue ia?aoth no?ieo e iiceoeeth neiaiea, aaea iie ?acee/atho-

ny.

Oi?aaeiaiea 7-4.

Ia?aaeaeaeoa i?ia?aiio iienea caaeaiiie eiiaeiaoeee neiai-

eia ec aeaau 5 oaeei ia?acii, /oiau a ea/anoaa aaiaea eniieue-

ciaaeny iaai? eiaiiaaiiuo oaeeia eee, anee ieeaeea oaeeu ia

oeacaiu eae a?aoiaiou, noaiaea?oiue aaiae. Neaaeoao ee ia/aoaoue

eiy oaeea i?e iaoiaeaeaiee iiaeoiaeyuae no?iee?

Oi?aaeiaiea 7-5.

Iaieoeoa i?ia?aiio ia/aoe iaai?a oaeeia, eioi?ay ia/eia-

ao eaaeaeue iiaue oaee n iiaie no?aieoeu e ia/aoaao aeey eaaeaeiai

oaeea caaieiaie e n/ao/ee oaeoueo no?aieoe.

7.9. Ianeieueei ?aciiia?aciuo ooieoeee

Noaiaea?oiay aeaeeioaea i?aaeinoaaeyao iiiaeanoai ?aciiia-

?aciuo ooieoeee, iaeioi?ua ec eioi?uo ieacuaathony iniaaiii

iieaciuie. Iu oaea oiiieiaee ooieoeee aeey ?aaiou ni no?ieaie:

STRLEN, STRCPY, STRCAT e STRCMP. Aio iaeioi?ua ae?oaea.

7.9.1. I?iaa?ea aeaea neiaieia e i?aia?aciaaiey

Iaeioi?ua iae?inu auiieiytho i?iaa?eo neiaieia e i?aia?a-

ciaaiey:

SALPHA© ia 0, anee “C” aeoaaeoiue neiaie,

0 – anee iao.

SUPPER© Ia 0, anee “C” aoeaa aa?oiaai ?aaeno?a,

0 – anee iao.

SLOWER© Ia 0, anee “C” aoeaa ieaeiaai ?aaeno?a,

0 – anee iao.

SDIGIT© Ia 0, anee “C” oeeo?a,

0 – anee iao.

SSPACL© Ia 0, anee “C” i?iaae, oaaoeyoeey

eee iiaay no?iea, 0 – anee iao.

OUPPER© I?aia?acoao “C” a aoeao aa?oiaai ?aaeno?a.

OLOWER© I?aia?acoao “C” a aoeao ieaeiaai ?aaeno?a.

7.9.2. Ooieoeey UNGETC

Noaiaea?oiay aeaeeioaea niaea?aeeo aeiaieueii ia?aie/aiioth

aa?neth ooieoeee UNGETCH, iaienaiiie iaie a aeaaa 4; iia iacu-

aaaony UNGETC. A ?acoeueoaoa ia?auaiey

UNGETC(C,FP)

neiaie “C” aica?auaaony a oaee FP. Iicaieyaony aica?auaoue a

eaaeaeue oaee oieueei iaeei neiaie. Ooieoeey UNGETC iiaeao auoue

eniieueciaaia a ethaie ec ooieoeee aaiaea e n iae?inaie oeia

SCANF, GETC eee GETCHAR.

· 166 –

7.9.3. Ia?auaiea e nenoaia

Ooieoeey SYSTEM(S) auiieiyao eiiaiaeo, niaea?aeauothny a nei-

aieueiie no?iea S, e caoai aiciaiiaeyao auiieiaiea oaeouae

i?ia?aiiu. Niaea?aeeiia S neeueii caaeneo io eniieuecoaiie iia-

?aoeeiiiie nenoaiu. A ea/anoaa o?eaeaeueiiai i?eia?a, oeaaeai,

/oi ia nenoaia UNIX no?iea

SYSTEM(“DATE”);

i?eaiaeeo e auiieiaieth i?ia?aiiu DATE, eioi?ay ia/aoaao aeaoo

e a?aiy aeiy.

7.9.4. Oi?aaeaiea iaiyoueth

Ooieoeey CALLOC aanueia noiaeia n ooieoeeae ALLOC, eniieueci-

aaiiie iaie a i?aaeuaeoueo aeaaao. A ?acoeueoaoa ia?auaiey

CALLOC(N, SIZEOF(OBJCCT))

aica?auaaony eeai oeacaoaeue i?ino?ainoaa, aeinoaoi/iiai aeey

?aciauaiey N iauaeoia oeacaiiiai ?acia?a, eeai NULL, anee

cai?in ia iiaeao auoue oaeaieaoai?ai. Ioaiaeeiay iaiyoue eieoeea-

eece?oaony ioeaauie cia/aieyie.

Oeacaoaeue iaeaaeaao ioaeiui aeey ?anniao?eaaaiuo iauaeoia

au?aaieaaieai, ii aio neaaeoao i?eienuaaoue niioaaonoaothuee

oei, eae a

CHAR *CALLOC();

INT *IP;

IP=(INT*) CALLOC(N,SIZEOF(INT));

Ooieoeey CFREE(P) inaiaiaeaeaao i?ino?ainoai, ia eioi?ia

oeacuaaao “P”, i?e/ai oeacaoaeue “P” iaaiia/aeueii aeieaeai auoue

iieo/ai a ?acoeueoaoa ia?auaiey e CALLOC. Caeanue iao ieeaeeo

ia?aie/aiee ia ii?yaeie inaiaiaeaeaiey i?ino?ainoaa, ii aoaeao

iai?eyoiaeoae ioeaeie inaiaiaeeoue /oi-ieaoaeue, /oi ia auei ii-

eo/aii ia?auaieai e CALLOC.

?aaeecaoeey i?ia?aiiu ?ani?aaeaeaiey iaiyoe, iiaeiaiie

CALLOC, a eioi?ie ?aciauaiiua aeiee iiaoo inaiaiaeaeaoueny a

i?iecaieueiii ii?yaeea, i?iaeaiiino?e?iaaia a aeaaa 8.

· 167 –

8. Eioa?oaen nenoaiu UNIX

Iaoa?eae yoie aeaau ioiineony e eioa?oaeno iaaeaeo n-i?ia-

?aiiaie e iia?aoeeiiiie nenoaiie UNIX. Oae eae aieueoeinoai

iieueciaaoaeae ycuea “C” ?aaioatho ia nenoaia UNIX, yoa aeaaa

ieaaeaony iieaciie aeey aieueoeinoaa /eoaoaeae. aeaaea anee au

eniieuecoaoa n-eiiieeyoi? ia ae?oaie iaoeia, eco/aiea i?eaiaee-

iuo caeanue i?eia?ia aeieaeii iiii/ue aai aeoaaea i?iieeiooue a ia-

oiaeu i?ia?aiie?iaaiey ia ycuea “C”.

Yoa aeaaa aeaeeony ia o?e iniiaiua /anoe: aaiae/auaiae,

nenoaia oaeeia e ?ani?aaeaeaiea iaiyoe. Ia?aua aeaa /anoe

i?aaeiieaaatho iaaieueoia ciaeiinoai n aiaoieie oa?aeoa?enoeea-

ie nenoaiu UNIX.

A aeaaa 7 iu eiaee aeaei n nenoaiiui eioa?oaenii, eioi?ue

iaeeiaeia aeey anaai iiiaiia?acey iia?aoeeiiiuo nenoai. Ia eaae-

aeie eiie?aoiie nenoaia ooieoeee noaiaea?oiie aeaeeioaee aeieaeiu

auoue iaienaiu a oa?ieiao aaiaea-auaiaea, aeinooiiuo ia aeaiiie

iaoeia. A neaaeothueo ianeieueeeo ?acaeaeao iu iieoai iniiaioth

nenoaio naycaiiuo n aaiaeii e auaiaeii oi/ae aoiaea iia?aoeeii-

iie nenoaiu UNIX e i?ieeethno?e?oai, eae n eo iiiiuueth iiaoo

auoue ?aaeeciaaiu ?acee/iua /anoe noaiaea?oiie aeaeeioaee.

8.1. Aeane?eioi?u oaeeia

A iia?aoeeiiiie nenoaia UNIX aanue aaiae e auaiae inouanoa-

eyaony iin?aaenoaii /oaiey oaeeia eee eo caiene, iioiio /oi

ana ia?eoa?eeiua ono?ienoaa, aeeth/ay aeaaea oa?ieiae iieueciaa-

oaey, yaeythony oaeeaie ii?aaeaeaiiie oaeeiaie nenoaiu. Yoi

icia/aao, /oi iaeei iaeii?iaeiue eioa?oaen oi?aaeyao anaie nay-

cyie iaaeaeo i?ia?aiiie e ia?eoa?eeiuie ono?ienoaaie.

A iaeaieaa iauai neo/aa ia?aae /oaieai ec oaeea eee ca-

ienueth a oaee iaiaoiaeeii niiaueoue nenoaia i aaoai iaia?aiee;

yoio i?ioeann iacuaaaony “ioe?uoeai” oaeea. Nenoaia auyniy-

ao,eiaaoa ee au i?aai iinooiaoue oaeei ia?acii (nouanoaoao ee

yoio oaee? eiaaony ee o aan ?ac?aoaiea ia ia?auaiea e ia-

io?), e anee ana a ii?yaeea, aica?auaao a i?ia?aiio iaaieueoia

iieiaeeoaeueiia oeaeia /enei, iacuaaaiia aeane?eioi?ii oaeea.

anyeee ?ac, eiaaea yoio oaee eniieuecoaony aeey aaiaea eee auai-

aea, aeey eaeaioeoeeaoeee oaeea oiio?aaeyaony aeane?eioi? oaeea,

a ia aai eiy. (Caeanue nouanoaoao i?eia?iay aiaeiaey n eniieue-

ciaaieai READ (5,…) e WRITE (6,…) a oi?o?aia). Any ei-

oi?iaoeey ia ioe?uoii oaeea niaea?aeeony a nenoaia; i?ia?aiia

iieueciaaoaey ia?auaaony e oaeeo oieueei /a?ac aeane?eioi? oae-

ea.

Aeey oaeianoaa auiieiaiey iau/iuo iia?aoeee aaiaea e auaiaea

n iiiiuueth oa?ieiaea iieueciaaoaey nouanoaotho niaoeeaeueiua nia-

eaoaiey. Eiaaea eioa?i?aoaoi? eiiaiae (“SHELL”) i?iaiiyao

i?ia?aiio, ii ioe?uaaao o?e oaeea, iacuaaaiua noaiaea?oiui

aaiaeii, noaiaea?oiui auaiaeii e noaiaea?oiui auaiaeii ioeaie,

eioi?ua eiatho niioaaonoaaiii /enea 0, 1 e 2 a ea/anoaa aeane-

?eioi?ia yoeo oaeeia. A ii?iaeueiii ninoiyiee ana iie naycaiu

n oa?ieiaeii, oae /oi anee i?ia?aiia /eoaao n aeane?eioi?ii

oaeea 0 e ieoao n aeane?eioi?aie oaeeia 1 e 2, oi iia iiaeao

inouanoaeyoue aaiae e auaiae n iiiiuueth oa?ieiaea, ia caaioynue

ia ioe?uoee niioaaonoaothueo oaeeia.

· 168 –

Iieueciaaoaeue i?ia?aiiu iiaeao ia?aiai?aaeyoue aaiae e auaiae

ia oaeeu, eniieuecoy iia?aoeee eiiaiaeiiai eioa?i?aoaoi?a SHELL

“” :

PROG OUTFILE

A yoii neo/aa eioa?i?aoaoi? eiiaiae SHELL eciaieo i?enaaeaa-

iea ii oiie/aieth aeane?eioi?ia oaeeia 0 e 1 n oa?ieiaea ia

oeacaiiua oaeeu. Ii?iaeueii aeane?eioi? oaeea 2 inoaaony nay-

caiiui n oa?ieiaeii, oae /oi niiauaiey ia ioeaeao iiaoo iin-

ooiaoue ooaea. Iiaeiaiua caia/aiey ni?aaaaeeeau e oiaaea, eiaaea

aaiae e auaiae naycai n eaiaeii. Neaaeoao ioiaoeoue, /oi ai anao

neo/ayo i?ee?aieaiey oaeeia eciaiythony eioa?i?aoaoi?ii

SHELL, a ia i?ia?aiiie. Naia i?ia?aiia, iiea iia eniieuecoao

oaee 0 aeey aaiaea e oaeeu 1 e 2 aeey auaiaea, ia ciaao ie ioeo-

aea i?eoiaeeo aa aaiae, ie eoaea iinooiaao aa auaea/a.

8.2. Ieceio?iaiaaue aaiae/auaiae – iia?aoi?u READ e WRITE.

Naiue ieceee o?iaaiue aaiaea/auaiaea a nenoaia UNIX ia i?a-

aeoniao?eaaao ie eaeie-eeai aooa?ecaoeee, ie eaeiai-eeai ae?o-

aiai na?aena; ii ii nouanoao yaeyaony iaiin?aaenoaaiiui aoi-

aeii a iia?aoeeiiioth nenoaio. Aanue aaiae e auaiae inouanoaeyaony

aeaoiy ooieoeeyie: READ e WRITE. Ia?aui a?aoiaioii iaaeo ooie-

oeee yaeyaony aeane?eioi? oaeea. Aoi?ui a?aoiaioii yaeyaony

aooa? a aaoae i?ia?aiia, ioeoaea eee eoaea aeieaeiu iinooiaoue

aeaiiua. O?aoee a?aoiaio – yoi /enei iiaeeaaeaueo ia?anueea

aaeoia. Ia?auaiey e yoei ooieoeeyi eiatho aeae:

N_READ=READ(FD,BUF,N);

N_WRITTEN=WRITE(FD,BUF,N);

I?e eaaeaeii ia?auaiee aica?auaaony n/ao/ee aaeoia, oeacuaath-

uee oaeoe/aneia /enei ia?aaeaiiuo aaeoia. I?e /oaiee aica?a-

uaiiia /enei aaeoia iiaeao ieacaoueny iaiueoa, /ai cai?ioaiiia

/enei. Aica?auaiiia ioeaaia /enei aaeoia icia/aao eiiaoe oae-

ea, a “-1” oeacuaaao ia iaee/ea eaeie-eeai ioeaee. I?e caie-

ne aica?auaiiia cia/aiea ?aaii /eneo oaeoe/anee caienaiiuo

aaeoia; ianiaiaaeaiea yoiai /enea n /eneii aaeoia, eioi?ia

i?aaeiieaaaeinue caienaoue, iau/ii naeaeaoaeuenoaoao ia ioeaea.

Eiee/anoai aaeoia, iiaeeaaeaueo /oaieth eee caiene, iiaeao

auoue niaa?oaiii i?iecaieueiui. Aeaoiy naiuie ?ani?ino?aiaiiuie

aaee/eiaie yaeythony “1”, eioi?ay icia/aao ia?aaea/o iaeiiai

neiaiea ca ia?auaiea (o.a. Aac eniieueciaaiey aooa?a), e

“512”, eioi?ay niioaaonoaoao oece/aneiio ?acia?o aeiea ia

iiiaeo ia?eoa?eeiuo ono?ienoaao. Yoio iineaaeiee ?acia? aoaeao

iaeaieaa yooaeoeaiui, ii aeaaea aaiae eee auaiae ii iaeiiio nei-

aieo ca ia?auaiea ia aoaeao iaiaueiiaaiii aei?iaei.

Iauaaeeiea ana yoe oaeou, iu iaienaee i?inooth i?ia?aiio

aeey eiie?iaaiey aaiaea ia auaiae, yeaeaaeaioioth i?ia?aiia ei-

ie?iaee oaeeia, iaienaiiie a aeaaa 1. Ia nenoaia UNIX yoa

i?ia?aiia aoaeao eiie?iaaoue /oi oaiaeii eoaea oaiaeii, iioiio

/oi aaiae e auaiae iiaoo auoue ia?aiai?aaeaiu ia ethaie oaee eee

ono?ienoai.

· 169 –

#DEFINE BUFSIZE 512 /*BEST SIZE FOR PDP-11 UNIX*/

MAIN() /*COPY INPUT TO OUTPUT*/

(

CHAR BUF[BUFSIZE];

INT N;

WHILE((N=READ(0,BUF,BUFSIZE))>0)

WRITE(1,BUF,N);

)

Anee ?acia? oaeea ia aoaeao e?aoai BUFSIZE, oi i?e iaeioi?ii

ia?auaiee e READ aoaeao aica?auaii iaiueoaa /enei aaeoia, ei-

oi?ua caoai caienuaathony n iiiiuueth WRITE; i?e neaaeothuai iin-

ea yoiai ia?auaiee e READ aoaeao aica?auai ioeue.

Iio/eoaeueii ?acia?aoueny, eae iiaeii eniieueciaaoue ooieoeee

READ e WRITE aeey iino?iaiey i?ioeaaeo? aieaa aunieiai o?iaiy,

oaeeo eae GETCHAR, PUTCHAR e o.ae. Aio, iai?eia?, aa?eaio

ooieoeee GETCHAR, inouanoaeythuee aaiae aac eniieueciaaiey aooa-

?a.

#DEFINE CMASK 0377 /*FOR MAKING CHAR’S > 0*/

GETCHAR() /*UNBUFFERED SINGLE CHARACTER INPUT*/

(

CHAR C;

RETURN((READ(0,&C,1)>0 7 & CMASK : EOF);

)

Ia?aiaiiay “C” aeieaeia auoue iienaia eae CHAR, iioiio /oi ooi-

eoeey READ i?eieiaao oeacaoaeue ia neiaieu. Aica?auaaiue nei-

aie aeieaeai auoue ianee?iaai /eneii 0377 aeey aa?aioee aai ii-

eiaeeoaeueiinoe; a i?ioeaiii neo/aa ciaeiaue ?ac?yae iiaeao naea-

eaoue aai cia/aiea io?eoeaoaeueiui. (Eiinoaioa 0377 iiaeoiaeeo

aeey yai PDP-11, ii ia iaycaoaeueii aeey ae?oaeo iaoei).

Aoi?ie aa?eaio ooieoeee GETCHAR inouanoaeyao aaiae aieueoe-

ie ii?oeeyie, a auaeaao neiaieu ii iaeiiio ca ia?auaiea.

#DEFINE CMASK 0377 /*FOR MAKING CHAR’S>0*/

#DEFINE BUFSIZE 512

GETCHAR() /*BUFFERED VERSION*/

(

STATIC CHAR BUF[BUFSIZE];

STATIC CHAR *BUFP = BUF;

STATIC INT N = 0;

IF (N==0) ( /*BUFFER IS EMPTY*/

N=READ(0,BUF,BUFSIZE);

BUFP = BUF;

)

RETURN((–N>=0) ? *BUFP++ & CMASK : EOF);

)

8.3. Ioe?uoea, nicaeaiea, cae?uoea e ?anoeaieaiea

(UNLINK).

E?iia neo/ay, eiaaea ii oiie/aieth ii?aaeaeaiu noaiaea?oiua

oaeeu aaiaea, auaiaea e ioeaie, au aeieaeiu yaii ioe?uaaoue oae-

eu, /oiau caoai /eoaoue ec ieo eee ienaoue a ieo. Aeey yoie oea-

ee nouanoaotho aeaa oi/ee aoiaea: OPEN e CREAT.

· 170 –

Ooieoeey OPEN aanueia noiaeia n ooieoeeae FOPEN, ?anniio?ai-

iie a aeaaa 7, ca eneeth/aieai oiai, /oi aianoi aica?auaiey

oeacaoaey oaeea iia aica?auaao aeane?eioi? oaeea, eioi?ue ya-

eyaony i?inoi oeaeui oeia INT.

INT FD;

FD=OPEN(NAME,RWMODE);

Eae e a neo/aa FOPEN, a?aoiaio NAME yaeyaony neiaieueiie

no?ieie, niioaaonoaothuae aiaoiaio eiaie oaeea. Iaeiaei a?ao-

iaio, ii?aaeaeythuee ?aaeei aeinooia, ioee/ai: RWMODE ?aaii: 0 –

aeey /oaiey, 1 – aeey caiene, 2 – aeey /oaiey e caiene. Anee

i?ienoiaeeo eaeay-oi ioeaea, ooieoeey OPEN aica?auaao “-1”; a

i?ioeaiii neo/aa iia aica?auaao aeaenoaeoaeueiue aeane?eioi?

oaeea.

Iiiuoea ioe?uoue oaee, eioi?ue ia nouanoaoao, yaeyaony

ioeaeie. Oi/ea aoiaea CREAT i?aaeinoaaeyao aiciiaeiinoue nicaea-

iey iiauo oaeeia eee ia?acaiene noa?uo. A ?acoeueoaoa ia?aua-

iey

FD=CREAT(NAME,PMODE);

aica?auaao aeane?eioi? oaeea, anee ieacaeinue aiciiaeiui nic-

aeaoue oaee n eiaiai NAME, e “-1” a i?ioeaiii neo/aa. Anee

oaee n oaeei eiaiai oaea nouanoaoao, CREAT ona/ao aai aei io-

eaaie aeeeiu; nicaeaiea oaeea, eioi?ue oaea nouanoaoao, ia ya-

eyaony ioeaeie.

Anee oaee yaeyaony niaa?oaiii iiaui, oi CREAT nicaeaao

aai n ii?aaeaeaiiui ?aaeeiii caueou, niaoeeoeoee?oaiui a?aoiai-

oii PMODE. A nenoaia oaeeia ia UNIX n oaeeii naycuaathony aea-

ayoue aeoia caueou eioi?iaoeee, eioi?ua oi?aaeytho ?ac?aoaieai

ia /oaiea, caienue e auiieiaiea aeey aeaaeaeueoea oaeea, aeey

a?oiiu aeaaeaeueoeaa e aeey anao inoaeueiuo iieueciaaoaeae. Oaeei

ia?acii, o?aocia/iia ainueia?e/iia /enei iaeaieaa oaeiaii aeey

niaoeeoeeaoeee ?ac?aoaiee. Iai?eia?, /enei 0755 naeaeaoaeuenoao-

ao i ?ac?aoaiee ia /oaiea, caienue e auiieiaiea aeey aeaaeaeueoea

e i ?ac?aoaiee ia /oaiea e auiieiaiea aeey a?oiiu e anao in-

oaeueiuo.

Aeey eeethno?aoeee ieaea i?eaiaeeony i?ia?aiia eiie?iaaiey

iaeiiai oaeea a ae?oaie, yaeythuayny oi?iuaiiui aa?eaioii ooe-

eeou CP nenoaiu UNIX. (Iniiaiia oi?iuaiea caeeth/aaony a oii,

/oi iao aa?eaio eiie?oao oieueei iaeei oaee e /oi aoi?ie a?ao-

iaio ia aeieaeai auoue ni?aai/ieeii).

#DEFINE NULL 0

#DEFINE BUFSIZE 512

#DEFINE PMODE 0644/*RW FOR OWNER,R FOR GROUP,OTHERS*/

MAIN(ARGC,ARGV) /*CP: COPY F1 TO F2*/

INT ARGC;

CHAR *ARGV[];

(

INT F1, F2, N;

CHAR BUF[BUFSIZE];

· 171 –

IF (ARGC ! = 3)

ERROR(“USAGE:CP FROM TO”, NULL);

IF ((F1=OPEN(ARGV[1],0))== -1)

ERROR(“CP:CAN’T OPEN %S”, ARGV[1]);

IF ((F2=CREAT(ARGV[2],PMODE))== -1)

ERROR(“CP: CAN’T CREATE %S”, ARGV[2]);

WHILE ((N=READ(F1,BUF,BUFSIZE))>0)

IF (WRITE(F2,BUF,N) !=N)

ERROR(“CP: WRITE ERROR”, NULL);

EXIT(0);

)

ERROR(S1,S2) /*PRINT ERROR MESSAGE AND DIE*/

CHAR *S1, S2;

(

PRINTF(S1,S2);

PRINTF(“N”);

EXIT(1);

)

Nouanoaoao ia?aie/aiea (iau/ii 15 – 25) ia eiee/anoai

oaeeia, eioi?ua i?ia?aiia iiaeao eiaoue ioe?uouie iaeiia?aiai-

ii. A niioaaonoaee n yoei ethaay i?ia?aiia, niae?athuayny ?a-

aioaoue ni iiiaeie oaeeaie, aeieaeia auoue iiaeaioiaeaia e iia-

oi?iiio eniieueciaaieth aeane?eioi?ia oaeeia. I?ioeaaeo?a CLOSE

i?a?uaaao naycue iaaeaeo aeane?eioi?ii oaeea e ioe?uoui oaeeii e

inaiaiaeaeaao aeane?eioi? oaeea aeey eniieueciaaiey n iaeioi?ui

ae?oaei oaeeii. Caaa?oaiea auiieiaiey i?ia?aiiu /a?ac EXIT

eee a ?acoeueoaoa aica?aoa ec aaaeouae i?ia?aiiu i?eaiaeeo e

cae?uoeth anao ioe?uouo oaeeia.

Ooieoeey ?anoeaieaiey UNLINK (FILENAME) oaeaeyao ec nenoaiu

oaeeia oaee n eiaiai FILENAME ( ec aeaiiiai ni?aai/iiai oae-

ea. Oaee iiaeao auoue noeaieai n ae?oaei ni?aai/ieeii, aiciiaeii,

iiae ae?oaei eiaiai – i?eia/.ia?aaiae/eea).

Oi?aaeiaiea 8-1.

Ia?aieoeoa i?ia?aiio CAT ec aeaau 7, eniieuecoy ooieoeee

READ, WRITE, OPEN e CLOSE aianoi eo yeaeaaeaioia ec noaiaea?-

oiie aeaeeioaee. I?iaaaeeoa yenia?eiaiou aeey ii?aaeaeaiey io-

iineoaeueiie nei?inoe ?aaiou yoeo aeaoo aa?eaioia.

8.4. I?iecaieueiue aeinooi – SEEK e LSEEK.

Ii?iaeueii i?e ?aaioa n oaeeaie aaiae e auaiae inouanoaey-

aony iineaaeiaaoaeueii: i?e eaaeaeii ia?auaiee e ooieoeeyi READ e

WRITE /oaiea eee caienue ia/eiathony n iiceoeee, iaiin?aaenoaai-

ii neaaeothuae ca i?aaeuaeouae ia?aaioaiiie. Ii i?e iaiaoiaeeiin-

oe oaee iiaeao /eoaoueny eee caienuaaoueny a ethaii i?iecaieueiii

ii?yaeea. Ia?auaiea e nenoaia n iiiiuueth ooieoeee LSEEK iicai-

eyao ia?aaeaeaaoueny ii oaeeo, ia i?iecaiaey oaeoe/aneiai /oa-

iey eee caiene. A ?acoeueoaoa ia?auaiey

LSEEK(FD,OFFSET,ORIGIN);

· 172 –

oaeouay iiceoeey a oaeea n aeane?eioi?ii FD ia?aaeaeaaaony ia

iiceoeeth OFFSET (niauaiea), eioi?ay ion/eouaaaony io ianoa,

oeacuaaaiiai a?aoiaioii ORIGIN (ia/aei ion/aoa). Iineaaeothuaa

/oaiea eee caienue aoaeoo oaia?ue ia/eiaoueny n yoie iiceoeee.

A?aoiaio OFFSET eiaao oei LONG; FD e ORIGIN eiatho oei INT.

A?aoiaio ORIGIN iiaeao i?eieiaoue cia/aiey 0,1 eee 2, oeacuaay

ia oi, /oi aaee/eia OFFSET aeieaeia ion/eouaaoueny niioaaono-

aaiii io ia/aea oaeea, io oaeouae iiceoeee eee io eiioea oae-

ea. Iai?eia?, /oiau aeiiieieoue oaee, neaaeoao ia?aae caienueth

iaeoe aai eiiaoe:

LSEEK(FD,0L,2);

/oiau aa?iooueny e ia/aeo (“ia?aiioaoue ia?aoii”), iiaeii iaie-

naoue:

LSEEK(FD,0L,0);

ia?aoeoa aieiaiea ia a?aoiaio 0L; aai iiaeii auei au caienaoue

e a aeaea (LONG) 0.

Ooieoeey LSEEK iicaieyao ia?auaoueny n oaeeaie i?eia?ii

oae aea, eae n aieueoeie ianneaaie, i?aaaea oeaiie aieaa iaaeeai-

iiai aeinooia. neaaeothuay i?inoay ooieoeey, iai?eia?, n/eouaaao

ethaia eiee/anoai aaeoia, ia/eiay n i?iecaieueiiai ianoa a

oaeea.

GET(FD,POS,BUF,N) /*READ N BYTES FROM POSITION POS*/

INT FD, N;

LONG POS;

CHAR *BUF;

(

LSEEK(FD,POS,0); /*GET TO POS*/

RETURN(READ(FD,BUF,N));

)

A aieaa ?aiieo ?aaeaeoeeyo, /ai ?aaeaeoeey 7 nenoaiu UNIX,

iniiaiay oi/ea aoiaea a nenoaio aaiaea-auaiaea iacuaaaony SEEK.

Ooieoeey SEEK eaeaioe/ia ooieoeee LSEEK, ca eneeth/aieai oiai,

/oi a?aoiaio OFFSET eiaao oei INT, a ia LONG. a niioaaonoaee

n yoei, iineieueeo ia PDP-11 oeaeua eiatho oieueei 16 aeoia, a?-

aoiaio OFFSET, oeacuaaaiue ooieoeee SEEK, ia?aie/ai aaee/eiie

65535; ii yoie i?e/eia a?aoiaio ORIGIN iiaeao eiaoue cia/aiey

3, 4, 5, eioi?ua canoaaeytho ooieoeeth SEEK oiiiaeeoue caaeaiiia

cia/aiea OFFSET ia 512 (eiee/anoai aaeoia a iaeiii oece/aneii

aeiea) e caoai eioa?i?aoe?iaaoue ORIGIN, eae anee yoi 0, 1

eee 2 niioaaonoaaiii. Neaaeiaaoaeueii, /oiau aeinoe/ue i?iec-

aieueiiai ianoa a aieueoii oaeea, ioaeii aeaa ia?auaiey e SEEK:

nia/aea iaeii, eioi?ia auaeaeyao ioaeiue aeie, a caoai aoi?ia,

aaea ORIGIN eiaao cia/aiea 1 e eioi?ia inouanoaeyao ia?aaeae-

aeaiea ia aeaeaaiue aaeo aioo?e aeiea.

Oi?aaeiaiea 8-2.

I/aaeaeii, /oi SEEK iiaeao auoue iaienaia a oa?ieiaeao

LSEEK e iaiai?io. iaieoeoa eaaeaeoth ooieoeeth /a?ac ae?oaoth.

· 173 –

8.5. I?eia? – ?aaeecaoeey ooieoeee FOPEN e GETC.

Aeaaaeoa oaia?ue ia i?eia?a ?aaeecaoeee ooieoeee FOPEN e

GETC ec noaiaea?oiie aeaeeioaee iiaei?ia?aii i?iaeaiiino?e?oai,

eae iaeioi?ua ec iienaiiuo yeaiaioia iauaaeeiythony aianoa.

Iaiiiiei, /oi a noaiaea?oiie aeaeeioaea oaeeu iienuaaony

iin?aaenoaii oeacaoaeae oaeeia, a ia aeane?eioi?ia. Oeacaoaeue

oaeea yaeyaony oeacaoaeai ia no?oeoo?o, eioi?ay niaea?aeeo

ianeieueei yeaiaioia eioi?iaoeee i oaeea: oeacaoaeue aooa?a,

/oiau oaee iia /eoaoueny aieueoeie ii?oeeyie; n/ao/ee /enea

neiaieia, inoaaoeony a aooa?a; oeacaoaeue neaaeothuae iiceoeee

neiaiea a aooa?a; iaeioi?ua i?eciaee, oeacuaathuea ?aaeei /oa-

iey eee caiene e o.ae.; aeane?eioi? oaeea.

Iienuaathuay oaee no?oeoo?a aeaiiuo niaea?aeeony a oaeea

STDIO.H, eioi?ue aeieaeai aeeth/aoueny (iin?aaenoaii #INCLUDE) a

ethaie enoiaeiue oaee, a eioi?ii eniieuecothony ooieoeee ec noai-

aea?oiie aeaeeioaee. Ii oaeaea aeeth/aaony ooieoeeyie yoie aea-

eeioaee. A i?eaiaeeiie ieaea auaea?aeea ec oaeea STDIO.H eiaia,

i?aaeiacia/aaiua oieueei aeey eniieueciaaiey ooieoeeyie aeaeeioa-

ee, ia/eiathony n iiae/a?eeaaiey, n oai /oiau oiaiueoeoue aa?i-

yoiinoue niaiaaeaiey n eiaiaie a i?ia?aiia iieueciaaoaey.

DEFINE _BUFSIZE 512

DEFINE _NFILE 20 /*FILES THAT CAN BE HANDLED*/

TYPEDEF STRUCT _IOBUF (

CHAR *_PTR; /*NEXT CHARACTER POSITION*/

INT _CNT; /*NUMBER OF CHARACTERS LEFT*/

CHAR *_BASE; /*LOCATION OF BUFFER*/

INT _FLAG; /*MODE OF FILE ACCESS*/

INT _FD; /*FILE DESCRIPTOR*/

) FILE;

XTERN FILE _IOB[_NFILE];

DEFINE STDIN (&_IOB[0])

DEFINE STDOUT (&_IOB[1])

DEFINE STDERR (&_IOB[2])

DEFINE _READ 01 /* FILE OPEN FOR READING */

DEFINE _WRITE 02 /* FILE OPEN FOR WRITING */

DEFINE _UNBUF 04 /* FILE IS UNBUFFERED */

DEFINE _BIGBUF 010 /* BIG BUFFER ALLOCATED */

DEFINE _EOF 020 /* EOF HAS OCCURRED ON THIS FILE */

DEFINE _ERR 040 /* ERROR HAS OCCURRED ON THIS FILE */

DEFINE NULL 0

DEFINE EOF (-1)

DEFINE GETC(P) (–(P)->_CNT >= 0

? *(P)->_PTR++ & 0377 : _FILEBUF(P))

DEFINE GETCHAR() GETC(STDIN)

DEFINE PUTC(X,P) (–(P)->_CNT >= 0

? *(P)->_PTR++ = (X) : _FLUSHBUF((X),P))

DEFINE PUTCHAR(X) PUTC(X,STDOUT)

· 174 –

A ii?iaeueiii ninoiyiee iae?in GETC i?inoi oiaiueoaao

n/ao/ee, ia?aaeaeaaao oeacaoaeue e aica?auaao neiaie. (Anee

ii?aaeaeaiea #DEFINE neeoeii aeeeiiia, oi iii i?iaeieaeaaony n

iiiiuueth ia?aoiie einie /a?ou). Anee iaeiaei n/ao/ee noaiiaeo-

ny io?eoeaoaeueiui, oi GETC aucuaaao ooieoeeth _FILEBUF, eioi?ay

niiaa caiieiyao aooa?, ?aeieoeeaeece?oao niaea?aeeiia no?oeoo?u

e aica?auaao neiaie. Ooieoeey iiaeao i?aaeinoaaeyoue ia?aiineiue

eioa?oaen e a oi aea a?aiy niaea?aeaoue iaia?aiineiua eiino?oe-

oeee: GETC ianee?oao neiaie /eneii 0377, eioi?ia iiaeaaeyao

ciaeiaia ?anoe?aiea, inouanoaeyaiia ia PDP-11, e oai naiui

aa?aioe?oao iieiaeeoaeueiinoue anao neiaieia.

Oioy iu ia niae?aainy ianoaeaeaoue eaeea-eeai aeaoaee, iu

ana aea aeeth/eee nthaea ii?aaeaeaiea iae?ina PUTC, aeey oiai /oi-

au iieacaoue, /oi iia ?aaioaao a iniiaiii oi/ii oaeaea, eae e

GETC, ia?auaynue i?e caiieiaiee aooa?a e ooieoeee _FLUSHBUF.

Oaia?ue iiaeao auoue iaienaia ooieoeey FOPEN. Aieueoay /anoue

i?ia?aiiu ooieoeee FOPEN naycaia n ioe?uaaieai oaeea e ?anii-

eiaeaieai aai a ioaeiii ianoa, a oaeaea n onoaiiaeaieai aeoia

i?eciaeia oaeei ia?acii, /oiau iie oeacuaaee ioaeiia ninoiy-

iea. Ooieoeey FOPEN ia auaeaeyao eaeie-eeai aooa?iie iaiyoe;

yoi aeaeaaony ooieoeeae _FILEBUF i?e ia?aii /oaiee ec oaeea.

#INCLUDE

#DEFINE PMODE 0644 /*R/W FOR OWNER;R FOR OTHERS*/

FILE *FOPEN(NAME,MODE) /*OPEN FILE,RETURN FILE PTR*/

REGISTER CHAR *NAME, *MODE;

(

REGISTER INT FD;

REGISTER FILE *FP;

IF(*MODE !=’R’&&*MODE !=’W’&&*MODE !=’A’) (

FPRINTF(STDERR,”ILLEGAL MODE %S OPENING %SN”,

MODE,NAME);

EXIT(1);

)

FOR (FP=_IOB;FP<_iob if>_FLAG & (_READ ! _WRITE))==0)

BREAK; /*FOUND FREE SLOT*/

IF(FP>=_IOB+_NFILE) /*NO FREE SLOTS*/

RETURN(NULL);

IF(*MODE==’W’) /*ACCESS FILE*/

FD=CREAT(NAME,PMODE);

ELSE IF(*MODE==’A’) (

IF((FD=OPEN(NAME,1))==-1)

FD=CREAT(NAME,PMODE);

LSEEK(FD,OL,2);

) ELSE

FD=OPEN(NAME,0);

IF(FD==-1) /*COULDN’T ACCESS NAME*/

RETURN(NULL);

FP->_FD=FD;

FP->_CNT=0;

FP->_BASE=NULL;

FP->_FLAG &=(_READ ! _WRITE);

FP->_FLAG !=(*MODE==’R’) ? _READ : _WRITE;

RETURN(FP);

)

· 175 –

Ooieoeey _FILEBUF ianeieueei aieaa neiaeiay. Iniiaiay o?oae-

iinoue caeeth/aaony a oii, /oi _FILEBUF no?aieony ?ac?aoeoue

aeinooi e oaeeo e a oii neo/aa, eiaaea iiaeao ia ieacaoueny aein-

oaoi/ii ianoa a iaiyoe aeey aooa?ecaoeee aaiaea eee auaiaea. an-

ee i?ino?ainoai aeey iiaiai aooa?a iiaeao auoue iieo/aii ia?a-

uaieai e ooieoeee CALLOC, oi ana ioee/ii; anee aea iao, oi

_FILEBUF inouanoaeyao iaaooa?eciaaiiue aaiae/ auaiae, eniieue-

coy ioaeaeueiue neiaie, iiiauaiiue a eieaeueiii ianneaa.

#INCLUDE

_FILLBUF(FP) /*ALLOCATE AND FILL INPUT BUFFER*/

REGISTER FILE *FP;

(

STATIC CHAR SMALLBUF(NFILE);/*FOR UNBUFFERED 1/0*/

CHAR *CALLOC();

IF((FR->_FLAG&_READ)==0!!(FP->_FLAG&(EOF!_ERR))!=0

RETURN(EOF);

WHILE(FP->_BASE==NULL) /*FIND BUFFER SPACE*/

IF(FP->_FLAG & _UNBUF) /*UNBUFFERED*/

FP->_BASE=&SMALLBUF[FP->_FD];

ELSE IF((FP->_BASE=CALLOC(_BUFSIZE,1))==NULL)

FP->_FLAG !=_UNBUF; /*CAN’T GET BIG BUF*/

ELSE

FP->_FLAG !=_BIGBUF; /*GOT BIG ONE*/

FP->_PTR=FP->_BASE;

FP->_CNT=READ(FP->_FD, FP->_PTR,

FP->_FLAG & _UNBUF ? 1 : _BUFSIZE);

FF(–FP->_CNT_CNT== -1)

FP->_FLAG ! = _EOF;

ELSE

FP->_FLAG ! = _ ERR;

FP->_CNT = 0;

RETURN(EOF);

)

RETURN(*FP->_PTR++ & 0377); /*MAKE CHAR POSITIVE*/

)

I?e ia?aii ia?auaiee e GETC aeey eiie?aoiiai oaeea n/ao/ee

ieacuaaaony ?aaiui ioeth, /oi i?eaiaeeo e ia?auaieth e

_FILEBUF. Anee ooieoeey _FILEBUF iaeaeao, /oi yoio oaee ia io-

e?uo aeey /oaiey, iia iaiaaeeaiii aica?auaao EOF. A i?ioeaiii

neo/aa iia iuoaaony auaeaeeoue aieueoie aooa?, a anee ae yoi ia

oaeaaony, oi aooa? ec iaeiiai neiaiea. I?e yoii iia caiineo a

_FLAG niioaaonoaothuoth eioi?iaoeeth i aooa?ecaoeee.

?ac aooa? oaea nicaeai, ooieoeey _FILEBUF i?inoi aucuaaao

ooieoeeth READ aeey aai caiieiaiey, onoaiaaeeaaao n/ao/ee e

oeacaoaee e aica?auaao neiaie ec ia/aea aooa?a.

Aaeeinoaaiiue inoaaoeeny iaauyniaiiui aii?in ninoieo a

oii, eae ana ia/eiaaony. Iannea _IOB aeieaeai auoue ii?aaeaeai e

eieoeeaeece?iaai aeey STDIN, STDOUT e STDERR:

· 176 –

FILE _IOB[NFILE] = (

(NULL,0,_READ,0), /*STDIN*/

(NULL,0,NULL,1), /*STDOUT*/

(NULL,0,NULL,_WRITE ! _UNBUF,2) /*STDERR*/

);

Ec eieoeeaeecaoeee /anoe _FLAG yoiai ianneaa no?oeoo? aeaeii,

/oi oaee STDIN i?aaeiacia/ai aeey /oaiey, oaee STDOUT – aeey

caiene e oaee STDERR – aeey caiene aac eniieueciaaiey aooa?a.

Oi?aaeiaiea 8-3.

Ia?aieoeoa ooieoeee FOPEN e _FILEBUF, eniieuecoy iiey

aianoi yaiuo iiaeoiauo iia?aoeee.

Oi?aaeiaiea 8-4.

?ac?aaioaeoa e iaieoeoa ooieoeee _FLUSHBUF e FCLOSE.

Oi?aaeiaiea 8-5.

Noaiaea?oiay aeaeeioaea niaea?aeeo ooieoeeth

FSEEK(FP, OFFSET, ORIGIN)

eioi?ay eaeaioe/ia ooieoeee LSEEK, eneeth/ay oi, /oi FP yaeyao-

ny oeacaoaeai oaeea, a ia aeane?eioi?ii oaeea. Iaieoeoa

FSEEK. Oaaaeeoanue, /oi aaoa FSEEK i?aaeeueii niaeanoaony n ao-

oa?ecaoeeae, naeaeaiiie aeey ae?oaeo ooieoeee aeaeeioaee.

8.6. I?eia? – ?ania/aoea ni?aai/ieeia

Eiiaaea o?aaoaony ae?oaie aeae acaeiiaeaenoaey n nenoaiie

oaeeia – ii?aaeaeaiea eioi?iaoeee i oaeea, a ia oiai, /oi a

iai niaea?aeeony. I?eia?ii iiaeao neoaeeoue eiiaiaea LS (“nienie

ni?aai/ieea”) nenoaiu UNIX. Ii yoie eiiaiaea ?ania/aouaathony

eiaia oaeeia ec ni?aai/ieea e, iaiaycaoaeueii, ae?oaay eioi?-

iaoeey, oaeay eae ?acia?u, ?ac?aoaiey e o.ae.

Iineieueeo, ii e?aeiae ia?a, ia nenoaia UNIX ni?aai/iee

yaeyaony i?inoi oaeeii, oi a oaeie eiiaiaea, eae LS iao ie/a-

ai iniaaiiiai; iia /eoaao oaee e auaeaeyao ioaeiua /anoe ec

iaoiaeyuaeny oai eioi?iaoeee. Iaeiaei oi?iao eioi?iaoeee ii?aaea-

eyaony nenoaiie, oae /oi LS aeieaeia ciaoue, a eaeii aeaea ana

i?aaenoaaeyaony a nenoaia.

Iu yoi /anoe/ii i?ieeethno?e?oai i?e iaienaiee i?ia?aiiu

FSIZE. I?ia?aiia FSIZE i?aaenoaaeyao niaie niaoeeaeueioth oi?io

LS, eioi?ay ia/aoaao ?acia?u anao oaeeia, oeacaiiuo a nienea

aa a?aoiaioia. Anee iaeei ec oaeeia yaeyaony ni?aai/ieeii, oi

aeey ia?aaioee yoiai ni?aai/ieea i?ia?aiia FSIZE ia?auaaony

naia e naaa ?aeo?neaii. anee aea a?aoiaiou aiiaua ionoonoao-

tho, oi ia?aaaouaaaony oaeouee ni?aai/iee.

Aeey ia/aea aeaaeei e?aoeee iaci? no?oeoo?u nenoaiu oaeeia.

Ni?aai/iee – yoi oaee, eioi?ue niaea?aeeo nienie eiai oaeeia e

iaeioi?ia oeacaiea i oii, aaea iie ?aciauathony. Oaeoe/anee

yoi oeacaiea yaeyaony eiaeaenii aeey ae?oaie oaaeeoeu, eioi?oth

iacuaatho “I – oceiaie oaaeeoeae”. Aeey oaeea I-ocae – yoi oi,

· 177 –

aaea niaea?aeeony any eioi?iaoeey i oaeea, ca eneeth/aieai aai

eiaie. Caienue a ni?aai/ieea ninoieo oieueei ec aeaoo yeaiai-

oia: iiia?a I-ocea e eiaie oaeea. Oi/iay niaoeeoeeaoeey iinoo-

iaao i?e aeeth/aiee oaeea SYS/DIR.H, eioi?ue niaea?aeeo

#DEFINE DIRSIZ 14 /*MAX LENGTH OF FILE NAME*/

STRUCT DIRECT /*STRUCTURE OF DIRECTORY ENTRY*/

(

INO_T&_INO; /*INODE NUMBER*/

CHAR &_NAME[DIRSIZ]; /*FILE NAME*/

);

“Oei” INO_T – yoi ii?aaeaeyaiue iin?aaenoaii TYPEDEF oei,

eioi?ue iienuaaao eiaeaen I-oceiaie oaaeeoeu. Ia PDP-11 UNIX

yoei oeiii ieacuaaaony UNSIGNED, ii yoi ia oio ni?o eioi?ia-

oeee, eioi?ue iiiauatho aioo?ue i?ia?aiiu: ia ?aciuo nenoaiao

yoio oei iiaeao auoue ?acee/iui. Iiyoiio e neaaeoao eniieueci-

aaoue TYPEDEF. Iieiue iaai? “nenoaiiuo” oeiia iaoiaeeony a

oaeea SYS/TUPES.H.

Ooieoeey STAT aa?ao eiy oaeea e aica?auaao anth niaea?aeauo-

thny a I-ii ocea eioi?iaoeeth ia yoii oaeea (eee -1, anee eia-

aony ioeaea). Oaeei ia?acii, a ?acoeueoaoa

STRUCT STAT STBUF;

CHAR *NAME;

STAT(NAME,&STBUF);

no?oeoo?a STBUF iaiieiyaony eioi?iaoeeae ec I-ai ocea i oaeea n eiaiai
NAME. No?oeoo?a, iienuaathuay aica?auaaioth ooieoeeae STAT eioi?iaoeeth,
iaoiaeeony a oaeea SYS/STAT.H e auaeyaeeo neaaeothuei ia?acii:

STRUCT STAT /*STRUCTURE RETURNED BY STAT*/

(

DEV_T ST_DEV; /* DEVICE OF INODE */

INO_T ST_INO; /* INODE NUMBER */

SHORT ST_MODE /* MODE BITS */

SHORT ST_NLINK; / *NUMBER OF LINKS TO FILE */

SHORT ST_UID; /* OWNER’S USER ID */

SHORT ST_GID; /* OWNER’S GROUP ID */

DEV_T ST_RDEV; /* FOR SPECIAL FILES */

OFF_T ST_SIZE; /* FILE SIZE IN CHARACTERS */

TIME_T ST_ATIME; /* TIME LAST ACCESSED */

TIME_T ST_MTIME; /* TIME LAST MODIFIED */

TIME_T ST_CTIME; /* TIME ORIGINALLY CREATED */

)

Aieueoay /anoue yoie eioi?iaoeee iauyniyaony a eiiiaioa?eyo.

Yeaiaio ST.MODE niaea?aeeo iaai? oeaaia, iienuaathueo oaee; aeey

oaeianoaa ii?aaeaeaiey oeaaia oaeaea iaoiaeyony a oaeea

SYS/STAT.H.

· 178 –

#DEFINE S_IFMT 0160000 /* TYPE OF FILE */

#DEFINE S_IFDIR 0040000 /* DIRECTORY */

#DEFINE S_IFCHR 0020000 /* CHARACTER SPECIAL */

#DEFINE S_IFBLK 0060000 /* BLOCK SPECIAL */

#DEFINE S_IFREG 0100000 /* REGULAR */

#DEFINE S_ISUID 04000 /* SET USER ID ON EXECUTION */

#DEFINE S_ISGID 02000 /* SET GROUP ID ON EXECUTION */

#DEFINE S_ISVTX 01000 /*SAVE SWAPPED TEXT AFTER USE*/

#DEFINE S_IREAD 0400 /* READ PERMISSION */

#DEFINE S_IWRITE 0200 /* WRITE PERMISSION */

#DEFINE S_IEXEC 0100 /* EXECUTE PERMISSION */

Oaia?ue iu a ninoiyiee iaienaoue i?ia?aiio FSIZE. Anee ii-

eo/aiiue io ooieoeee STAT ?aaeei oeacuaaao, /oi oaee ia yaey-

aony ni?aai/ieeii, oi aai ?acia? oaea iiae ?oeie e iiaeao auoue

iaia/aoai iaiin?aaenoaaiii. Anee aea ii ieacuaaaony ni?aai/ie-

eii, oi iu aeieaeiu ia?aaaouaaoue yoio ni?aai/iee ioaeaeueii aeey

eaaeaeiai oaeea; oae eae ni?aai/iee iiaeao a naith i/a?aaeue ni-

aea?aeaoue iiaeni?aai/ieee, yoio i?ioeann ia?aaioee yaeyaony ?a-

eo?neaiui.

Eae iau/ii, aaaeouay i?ia?aiia aeaaiui ia?acii eiaao aeaei

n eiiaiaeiie no?ieie a?aoiaioia; iia ia?aaeaao eaaeaeue a?aoiaio

ooieoeee FSIZE a aieueoie aooa?.

#INCLUDE

#INCLUDE /*TYPEDEFS*/

#INCLUDE /*DIRECTORY ENTRY STRUCTURE*/

#INCLUDE /*STRUCTURE RETURNED BY STAT*/

#DEFINE BUFSIZE 256

MAIN(ARGC,ARGV) /*FSIZE:PRINT FILE SIZES*/

CHAR *ARGV[];

(

CHAR BUF[BUFSIZE];

IF(ARGC==1) ( /*DEFAULT:CURRENT DIRECTORY*/

ATRCPY(BUF,”.”);

FSIZE(BUF);

) ELSE

WHILE(–ARGC>0) (

STRCPY(BUF,*++ARGV);

FSIZE(BUF);

)

)

Ooieoeey FSIZE ia/aoaao ?acia? oaeea. Anee iaeiaei oaee

ieacuaaaony ni?aai/ieeii, oi FSIZE nia/aea aucuaaao ooieoeeth

DIRECTORY aeey ia?aaioee anao oeacaiiuo a iai oaeeia. Ia?aoe-

oa aieiaiea ia eniieueciaaiea eiai oeaaia S_IFMT e _IFDIR ec

oaeea STAT.H.

· 179 –

FSIZE(NAME) /*PRINT SIZE FOR NAME*/

CHAR *NAME;

(

STRUCT STAT STBUF;

IF(STAT(NAME,&STBUF)== -1) (

FPRINTF(STDERR,”FSIZE:CAN’T FIND %SN”,NAME);

RETURN;

)

IF((STBUF.ST_MODE & S_IFMT)==S_IFDIR)

DIRECTORY(NAME);

PRINTF(“%8LD %SN”,STBUF.ST_SIZE,NAME);

)

Ooieoeey DIRECTORY yaeyaony naiie neiaeiie. Iaeiaei cia/e-

oaeueiay aa /anoue naycaia n nicaeaieai aeey ia?aaaouaaaiiai a

aeaiiue iiiaio oaeea aai iieiiai eiaie, ii eioi?iio iiaeii

ainnoaiiaeoue iooue a aea?aaa.

DIRECTORY(NAME) /*FSIZE FOR ALL FILES IN NAME*/

CHAR *NAME;

(

STRUCT DIRECT DIRBUF;

CHAR *NBP, *NEP;

INT I, FD;

NBP=NAME+STRLEN(NAME);

*NBP++=’/’; /*ADD SLASH TO DIRECTORY NAME*/

IF(NBP+DIRSIZ+2>=NAME+BUFSIZE) /*NAME TOO LONG*/

RETURN;

IF((FD=OPEN(NAME,0))== -1)

RETURN;

WHILE(READ(FD,(CHAR *)&DIRBUF,SIZEOF(DIRBUF))>0) (

IF(DIRBUF.D_INO==0) /*SLOT NOT IN USE*/

CONTINUE;

IF(STRCMP (DIRBUF.D_NAME,”.”)==0

!! STRCMP(DIRBUF.D_NAME,”..”)==0

CONTINUE; /*SKIP SELF AND PARENT*/

FOR (I=0,NEP=NBP;IS.PTR; ; G=P, P=P->S.PTR) (

IF (P->S.SIZE>=NUNITS) ( /*BIG ENOUGH*/

IF (P->S.SIZE==NUNITS) /*EXACTLY*/

G->S.PTR=P->S.PTR;

ELSE ( /*ALLOCATE TAIL END*/

P->S.SIZE-=NUNITS;

P+=P->S.SIZE;

P->S.SIZE=NUNITS;

)

ALLOCP=G;

RETURN((CHAR *)(P+1));

)

IF(P==ALLOCP) /*WRAPPED AROUND FREE LIST*/

IF((P=MORECORE(NUNITS))==NULL)

RETURN(NULL); /*NONE LEFT*/

)

)

Ia?aiaiiay BASE eniieuecoaony aeey ia/aea ?aaiou. Anee

ALLOCP eiaao cia/aiea NULL, eae a neo/aa ia?aiai ia?auaiey e

ALLOC, oi nicaeaaony au?iaeaeaiiue naiaiaeiue nienie: ii ninoieo

ec naiaiaeiiai aeiea ?acia?a ioeue e oeacaoaey ia naiiai naay.

A ethaii neo/aa caoai enneaaeoaony naiaiaeiue nienie. Iiene

naiaiaeiiai aeiea iiaeoiaeyuaai ?acia?a ia/eiaaony n oiai ianoa

(ALLOCP), aaea aue iaeaeai iineaaeiee aeie; oaeay no?aoaaey ii-

iiaaao nio?aieoue iaeii?iaeiinoue aeenea. Anee iaeaeai neeoeii

aieueoie aeie, oi iieueciaaoaeth i?aaeeaaaaony aai oainoiaay

/anoue; yoi i?eaiaeeo e oiio, /oi a caaieiaea enoiaeiiai aeiea

ioaeii eciaieoue oieueei aai ?acia?. Ai anao neo/ayo aica?auaa-

iue iieueciaaoaeth oeacaoaeue oeacuaaao ia aeaenoaeoaeueii nai-

aiaeioth iaeanoue, eaaeauoth ia aaeeieoeo aeaeueoa caaieiaea. Ia?aoe-

oa aieiaiea ia oi, /oi ooieoeey ALLOC ia?aae aica?auaieai “P”

i?aia?acoao aai a oeacaoaeue ia neiaieu.

Ooieoeey MORECORE iieo/aao iaiyoue io iia?aoeeiiiie nenoa-

iu. Aeaoaee oiai, eae yoi inouanoaeyaony, iaiythony, eiia/ii,

io nenoaiu e nenoaia. Ia nenoaia UNIX oi/ea aoiaea SBRK(N)

aica?auaao oeacaoaeue ia “N” aeiiieieoaeueiuo aaeoia iaiy-

oe.(oeacaoaeue oaeaieaoai?yao anai ia?aie/aieyi ia au?aaieaa-

iea). Oae eae cai?in e nenoaia ia auaeaeaiea iaiyoe yaeyaony

n?aaieoaeueii aei?iaie iia?aoeeae, iu ia oioei aeaeaoue yoi i?e

eaaeaeii ia?auaiee e ooieoeee ALLOC. Iiyoiio ooieoeey MORECORE

ie?oaeyao cao?aaiaaiiia /enei aaeeieoe aei aieueoaai cia/aiey;

yoio aieueoee aeie aoaeao caoai ?acaeaeai oae, eae iaiaoiaeeii.

Ianooaae?othuay aaee/eia yaeyaony ia?aiao?ii, eioi?ue iiaeao

auoue iiaeia?ai a niioaaonoaee n iaiaoiaeeiinoueth.

· 183 –

#DEFINE NALLOC 128 /*#UNITS TO ALLOCATE AT ONCE*/

STATIC HEADER *MORECORE(NU) /*ASK SYSTEM FOR MEMORY*/

UNSIGNED NU;

(

CHAR *SBRK();

REGISTER CHAR *CP;

REGISTER HEADER *UP;

REGISTER INT RNU;

RNU=NALLOC*((NU+NALLOC-1)/NALLOC);

CP=SBRK(RNU*SIZEOF(HEADER));

IF ((INT)CP==-1) /*NO SPACE AT ALL*/

RETURN(NULL);

UP=(HEADER *)CP;

UP->S.SIZE=RNU;

FREE((CHAR *)(UP+1));

RETURN(ALLOCP);

)

Anee aieueoa ia inoaeinue naiaiaeiiai i?ino?ainoaa, oi ooi-

eoeey SBRK aica?auaao “-1”, oioy NULL aue au eo/oei auai?ii.

Aeey iaaeaaeiinoe n?aaiaiey “-1” aeieaeia auoue i?aia?aciaaia e

oeio INT. Niiaa i?eoiaeeony iiiaie?aoii eniieueciaaoue yaiua

i?aia?aciaaiey (ia?aaiae) oeiia, /oiau iaania/eoue ii?aaeaeai-

ioth iacaaeneiinoue ooieoeee io aeaoaeae i?aaenoaaeaiey oeacaoa-

eae ia ?acee/iuo iaoeiao.

E iineaaeiaa – naia ooieoeey FREE. Ia/eiay n ALLOCP, iia

i?inoi i?iniao?eaaao naiaiaeiue nienie a iienea ianoa aeey

aaaaeaiey naiaiaeiiai aeiea. Yoi ianoi iaoiaeeony eeai iaaeaeo

aeaoiy nouanoaothueie aeieaie, eeai a iaeiii ec eiioeia nienea.

A ethaii neo/aa, anee inaiaiaeeaoeeny aeie i?eiueaao e iaeiiio

ec ninaaeieo, niaaeiua aeiee iauaaeeiythony. Neaaeeoue ioaeii oieue-

ei caoai, /oiau oeacaoaee oeacuaaee ia oi, /oi ioaeii, e /oi-

au ?acia?u auee onoaiiaeaiu i?aaeeueii.

FREE(AP) /*PUT BLOCKE AP IN FREE LIST*/

CHAR *AP;

(

REGISTER HEADER *P, *G;

P=(HEADER*)AP-1; /*POINT TO HEADER*/

FOR (G=ALLOCP; !(P>G && P>G->S.PTR);G=G->S.PTR)

IF (G>=G->S.PTR && (P>G !! PS.PTR))

BREAK; /*AT ONE END OR OTHER*/

IF (P+P->S.SIZE==G->S.PTR)(/*JOIN TO UPPER NBR*/

P->S.SIZE += G->S.PTR->S.SIZE;

P->S.PTR = G->S.PTR->S.PTR;

) ELSE

P->S.PTR = G->S.PTR;

IF (G+G->S.SIZE==P) ( /*JOIN TO LOWER NBR*/

G->S.SIZE+=P->S.SIZE;

G->S.PTR=P->S.PTR;

) ELSE

G->S.PTR=P;

ALLOCP = G;

)

· 184 –

Oioy ?ani?aaeaeaiea iaiyoe ii naiae nooe caaeneo io en-

iieuecoaiie iaoeiu, i?eaaaeaiiay auoa i?ia?aiia iieacuaaao,

eae yoo caaeneiinoue iiaeii ?aaoee?iaaoue e ia?aie/eoue aanueia

iaaieueoie /anoueth i?ia?aiiu. Eniieueciaaiea TYPEDEF e UNION

iicaieyao ni?aaeoueny n au?aaieaaieai (i?e oneiaee, /oi ooie-

oeey SBRK iaania/eaaao iiaeoiaeyuee oeacaoaeue). Ia?aaiaeu oeiia

i?aaiecotho auiieiaiea yaiiai i?aia?aciaaiey oeiia e aeaaea

ni?aaeythony n iaoaea/ii ?ac?aaioaiiui nenoaiiui eioa?oaenii.

E oioy ?anniio?aiiua caeanue iiae?iaiinoe naycaiu n ?ani?aaeaea-

ieai iaiyoe, iauee iiaeoiae ?aaiui ia?acii i?eiaiei e e ae?oaei

neooaoeeyi.

Oi?aaeiaiea 8-6.

Ooieoeey ec noaiaea?oiie aeaeeioaee CALLOC(N,SIZE) aica?a-

uaao oeacaoaeue ia “N” iauaeoia ?acia?a SIZE, i?e/ai niioaao-

noaothuay iaiyoue eieoeeaeece?oaony ia ioeue. iaieoeoa i?ia?aiio

aeey CALLOC, eniieuecoy ooieoeeth ALLOC eeai a ea/anoaa ia?acoea,

eeai eae ooieoeeth, e eioi?ie i?ienoiaeeo ia?auaiea.

Oi?aaeiaiea 8-7.

Ooieoeey ALLOC i?eieiaao cao?aaiaaiiue ?acia?, ia i?iaa-

?yy aai i?aaaeiiiaeiaiinoe; ooieoeey FREE iieaaaao, /oi oio

aeie, eioi?ue iia aeieaeia inaiaiaeeoue, niaea?aeeo i?aaeeueiia

cia/aiea a iiea ?acia?a. Oniaa?oainoaoeoa yoe i?ioeaaeo?u,

cao?aoea aieueoa oneeee ia i?iaa?eo ioeaie.

Oi?aaeiaiea 8-8.

Iaieoeoa ooieoeeth BFREE(P,N), eioi?ay aeeth/aao i?iecaieue-

iue aeie “P” ec “N” neiaieia a nienie naiaiaeiuo aeieia, oi-

?aaeyaiue ooieoeeyie ALLOC e FREE. N iiiiuueth ooieoeee BFREE

iieueciaaoaeue iiaeao a ethaia a?aiy aeiaaaeyoue a naiaiaeiue nie-

nie noaoe/aneee eee aiaoiee iannea.

· 185 –

9. I?eeiaeaiea A: ni?aai/iia ?oeiaiaenoai ii ycueo ‘C’

9.1. Aaaaeaiea

Yoi ?oeiaiaenoai iienuaaao ycue ‘n’ aeey eiiiuethoa?ia DEC

PDP-11, HONEYWELL 6000, IBM nenoaia/370 e INTERDATA 8/32.

oai, aaea anoue ?anoiaeaeaiey, iu nin?aaeioa/eaaainy ia aa?nee

aeey PDP-11, no?aiynue a oi aea a?aiy oeacaoue aeaoaee, eioi?ua

caaenyo io ?aaeecaoeee. Ca iaeui eneeth/aieai, yoe ?anoiaeaeaiey

iaiin?aaenoaaiii iaoneiaeaiu iniiaiuie naienoaaie eniieuecoa-

iiai aiia?aoiiai iai?oaeiaaiey; ?acee/iua eiiieeyoi?u iau/ii

aiieia niaianoeiu.

10. Eaene/aneea niaeaoaiey

Eiaaony oanoue eeannia eaenai: eaeaioeoeeaoi?u, eeth/aaua

neiaa, eiinoaiou, no?iee, iia?aoeee e ae?oaea ?acaeaeeoaee.

I?iaaeu, oaaoeyoeee , iiaua no?iee e eiiiaioa?ee (niaianoii,

“ionoua i?iiaaeooee”), eae iienaii ieaea, eaii?e?othony, ca en-

eeth/aieai oao neo/aaa, eiaaea iie neoaeao ?acaeaeeoaeyie eae-

nai. Iaiaoiaeei eaeie-oi ionoie i?iiaaeooie aeey ?acaeaeaiey

eaeaioeoeeaoi?ia, eeth/aauo neia e eiinoaio, eioi?ua a i?ioea-

iii neo/aa nieuethony.

Anee naeaeai ?acai? aoiaeiiai iioiea ia eaenaiu aieioue aei

aeaiiiai neiaiea, oi a ea/anoaa neaaeothuae eaenaiu aa?aony na-

iay aeeeiiay no?iea neiaieia, eioi?ay aua iiaeao i?aaenoaaeyoue

niaie eaenaio.

10.1. Eiiiaioa?ee

Eiiiaioa?ee ioe?uaaaony neiaieaie /* e caeai/eaaaony

neiaieaie /*. Eiiiaioa?ee ia aeeaaeuaathony ae?oa a ae?oaa.

10.2. Eaeaioeoeeaoi?u (eiaia)

Eaeaioeoeeaoi? – yoi iineaaeiaaoaeueiinoue aoea e oeeo?; ia?-

aue neiaie aeieaeai auoue aoeaie. Iiae/a?eeaaiea _ n/eoaaony

aoeaie. Aoeau ieaeiaai e aa?oiaai ?aaeno?ia ?acee/athony. cia-

/aueie yaeythony ia aieaa, /ai ia?aua ainaiue neiaieia, oioy

iiaeii eniieueciaaoue e aieueoa. Ia aiaoiea eaeaioeoeeaoi?u, ei-

oi?ua eniieuecothony ?acee/iuie annaiaea?aie e caa?oc/eeaie,

iaeeaaeuaaony aieaa aeanoeea ia?aie/aiey:

DEC PDP-11 7 neiaieia, 2 ?aaeno?a

HONEYWELL 6000 6 neiaieia, 1 ?aaeno?

IBM 360/370 7 neiaieia, 1 ?aaeno?

INTERDATA 8/32 8 neiaieia, 2 ?aaeno?a

· 186 –

10.3. Eeth/aaua neiaa

Neaaeothuea eaeaioeoeeaoi?u ca?aca?ae?iaaiu aeey eniieueciaa-

iey a ea/anoaa eeth/aauo neia e ia iiaoo eniieueciaaoueny eiui

ia?acii:

INT EXTERN ELSE

CHAR REGISTER FOR

FLOAT TYPEDEF DO

DOUBLE STATIC WHILE

STRUCT GOTO SWITCH

UNION RETURN CASE

LONG SIZEOF DEFAULT

SHORT BREAK ENTRY

UNSIGNED CONTINUE

*AUTO IF

Eeth/aaia neiai ENTRY a ianoiyuaa a?aiy ia eniieuecoaony ea-

eei-eeai eiiieeyoi?ii; iii ca?aca?ae?iaaii aeey eniieueciaaiey

a aoaeouai. A iaeioi?uo ?aaeecaoeeyo ?aca?ae?oaony oaeaea neiaa

FORTRAN e ASM

10.4. Eiinoaiou

Eiaaony ianeieueei aeaeia eiinoaio, eioi?ua ia?a/eneaiu ieaea.

A ioieoa 10.6 ?acthie?othony oa?aeoa?enoeee aiia?aoiuo n?aae-

noa, eioi?ua aeeytho ia ?acia?u.

10.4.1. Oeaeua eiinoaiou

Oeaeay eiinoaioa, ninoiyuay ec iineaaeiaaoaeueiinoe oeeo?,

n/eoaaony ainueia?e/iie, anee iia ia/eiaaony n 0 (oeeo?a

ioeue), e aeanyoe/iie a i?ioeaiii neo/aa. Oeeo?u 8 e 9 eiatho

ainueia?e/iua cia/aiey 10 e 11 niioaaonoaaiii. Iineaaeiaaoaeue-

iinoue oeeo?, eioi?ie i?aaeoanoaotho neiaieu 0o (ioeue, o-iaeaiue-

eia) eee 0o (ioeue o-aieueoia), ?anniao?eaaaony eae oanoiaaeoea-

oe?e/iia oeaeia. Oanoiaaeoeaoe?e/iua oeeo?u aeeth/atho aoeau io a

(iaeaiueeia) eee a (aieueoia) aei F (iaeaiueeia) eee F (aieueoia)

ni cia/aieyie io 10 aei 15. Aeanyoe/iay eiinoaioa, aaee/eia

eioi?ie i?aauoaao iaeaieueoaa iaoeiiia oeaeia ni ciaeii, n/e-

oaaony aeeeiiie; ainia?e/iay eee oanoiaaeoeaoe?e/iay eiinoaioa,

eioi?ia i?aauoaao iaeaieueoaa iaoeiiia oeaeia aac ciaea, oaeaea

n/eoaaony aeeeiiie.

10.4.2. ssaiua aeeeiiua eiinoaiou

Aeanyoe/iay, ainia?e/iay eee oanoiaaeoeaoe?e/iay eiinoaioa,

ca eioi?ie iaiin?aaenoaaiii neaaeoao L (yeue-iaeaiueeia) eee L

(yeue-aieueoia), yaeyaony aeeeiiie eiinoaioie. Eae ianoaeaeaaony

ieaea, ia iaeioi?uo iaoeiao oeaeua e aeeeiiua cia/aiey iiaoo

?anniao?eaaoueny eae eaeaioe/iua.

10.4.3. Neiaieueiua eiinoaiou

Neiaieueiay eiinoaioa – yoi neiaie, caeeth/aiiue a iaeeii/-

iua eaau/ee, eae, iai?eia?, ‘X’. Cia/aieai neiaieueiie eiin-

oaiou yaeyaony /eneaiiia cia/aiea yoiai neiaiea a iaoeiiii

i?aaenoaaeaiee iaai?a neiaieia.

· 187 –

Iaeioi?ua iaa?aoe/aneea neiaieu, iaeeii/iay eaau/ea ‘ e

ia?aoiay einay /a?oa iiaoo auoue i?aaenoaaeaiu a niioaaono-

aee ni neaaeothuae oaaeeoeae oneiaiuo iineaaeiaaoaeueiinoae:

iiaay no?iea NL/LF/ N

ai?eciioaeueiay oaaoeyoeey HT T

neiaie aica?aoa ia iaeio iiceoeeth BS B

aica?ao ea?aoee CR R

ia?aoiae ia iiaoth no?aieoeo FF F

ia?aoiay einay /a?oa

iaeeii/iay eaau/ea ‘ ‘

eiiaeiaoeey aeoia DDD DDD

Oneiaiay iineaaeiaaoaeueiinoue DDD ninoieo ec ia?aoiie ei-

nie /a?ou, ca eioi?ie neaaeotho 1,2 eee 3 ainia?e/iuo oeeo?u,

eioi?ua ?anniaoeaathony eae caaeathuea cia/aiea aeaeaaiiai nei-

aiea. Niaoeeaeueiui neo/aai yoie eiino?oeoeee yaeyaony iineaaei-

aaoaeueiinoue 0 (ca ioeai ia neaaeoao oeeo?a), eioi?ay ii?aaea-

eyao neiaie NUL. anee neaaeothuee ca ia?aoiie einie /a?oie

neiaie ia niaiaaeaao n iaeiei ec oeacaiiuo, oi ia?aoiay einay

/a?oa eaii?e?oaony.

10.4.4. Ieaaathuea eiinoaiou

Ieaaathuay eiinoaioa ninoieo ec oeaeie /anoe, aeanyoe/iie

oi/ee, ae?iaiie /anoe, aoeau E (iaeaiueeay) eee E (aieueoay) e

oeaeie yeniiiaiou n iaiaycaoaeueiui ciaeii. Eae oeaeay, oae e

ae?iaiay /anoue yaeythony iineaaeiaaoaeueiinoueth oeeo?. Eeai oeaeay,

eeai ae?iaiay /anoue (ii ia iaa) iiaeao ionoonoaiaaoue; eeai aea-

nyoe/iay oi/ea, eeai a (iaeaiueeay) e yeniiiaioa (ii ia oi e

ae?oaia iaeiia?aiaiii) iiaeao ionoonoaiaaoue. Eaaeaeay ieaaathuay

eiinoaioa n/eoaaony eiathuae aeaieioth oi/iinoue.

10.5. No?iee

No?iea – yoi iineaaeiaaoaeueiinoue neiaieia, caeeth/aiiay a

aeaieiua eaau/ee, eae, iai?eeia?,”…”. No?iea eiaao oei

“iannea ianneaia” e eeann iaiyoe STATIC (ni. Ioieo 4 ieaea).

No?iea eieoeeaeece?iaaia oeacaiiuie a iae neiaieaie. Ana

no?iee, aeaaea eaeaioe/ii caienaiiua, n/eoathony ?acee/iuie.

Eiiieeyoi? iiiauaao a eiiaoe eaaeaeie no?iee ioeaaie aaeo 0, n

oai /oiau i?iniao?eaathuay no?ieo i?ia?aiia iiaea ii?aaeaeeoue

aa eiiaoe. Ia?aae noiyuei aioo?e no?iee neiaieii aeaieiie ea-

au/ee “ aeieaeai auoue iinoaaeai neiaie ia?aoiie einie /a?ou ;

e?iia oiai, iiaoo eniieueciaaoueny oa aea oneiaey iineaaeiaa-

oaeueiinoe, /oi e a neiaieueiuo eiinoaioao. E iineaaeiaa, ia-

?aoiay einay /a?oa , ca eioi?ie iaiin?aaenoaaiii neaaeoao

neiaie iiaie no?iee, eaii?e?oaony.

· 188 –

10.6. Oa?aeoa?enoeee aiia?aoiuo n?aaenoa

Neaaeothuay ieaea oaaeeoea noiie?oao iaeioi?ua naienoaa ai-

ia?aoiiai iai?oaeiaaiey, eioi?ua iaiythony io iaoeiu e iaoeia.

Oioy iie e aeeytho ia ia?aiineiinoue i?ia?aii, ia i?aeoeea iie

i?aaenoaaeytho iaeaiueeoth i?iaeaio, /ai yoi iiaeao eacaoueny ca-

?aiaa.

Oaaeeoea 1

DEC PDP-11 HONEYWELL IBM 370 INTERDATA 8/32

ASCII ASCII EBCDIC ASCII

CHAR 8 BITS 9 BITS 8 BITS 8 BITS

INT 16 36 32 32

SHORT 16 36 16 16

LONG 32 36 32 32

FLOAT 32 36 32 32

DOUBLE 64 72 64 64

RANGE -38/+38 -38/+38 -76/+76 -76/+76

11. Neioaene/aneay iioaoeey

A eniieuecoaiie a yoii ?oeiaiaenoaa neioaene/aneie iioaoeee

neioaene/aneea eaoaai?ee auaeaeythony eo?neaii (i?ei. ia?aa.:

a ianoiyuaa a?aiy neioaene/aneea eaoaai?ee aianoi eo?neaii

auaeaeythony iiae/a?eeaaieai), a eeoa?iua neiaa e neiaieu –

aee?iui o?eooii. Aeueoa?iaoeaiua eaoaai?ee ia?a/eneythony ia

ioaeaeueiuo no?i/eao. Iaiaycaoaeueiue neiaie, oa?ieiaeueiue eee

iaoa?ieiaeueiue, oeacuaaaony eiaeaenii “iaia”, oae /oi

( au?aaeaiea

——— iaia )

oeacuaaao ia iaiaycaoaeueiia au?aaeaiea, caeeth/aiiia a oeao?-

iuo neiaeao. Neioaenen noiie?oaony a ioieoa 18.

12. *oi a eiaia oaaa iiai?

sscue “C” iniiauaaao eioa?i?aoaoeeth eaeaioeoeeaoi?a ia aeaoo

i?eciaeao eaeaioeoeeaoi?a: aai eeanna iaiyoe e aai oeia.

Eeann iaiyoe ii?aaeaeyao ianoi e a?aiy o?aiaiey iaiyoe, nay-

caiiie n eaeaioeoeeaoi?ii; oei ii?aaeaeyao niune aaee/ei, ia-

oiaeyueony a iaiyoe, ii?aaeaeaiiie iiae eaeaioeoeeaoi?ii.

Eiathony /aou?a eeanna iaiyoe: aaoiiaoe/aneay, noaoe/an-

eay, aiaoiyy e ?aaeno?iaay. Aaoiiaoe/aneea ia?aiaiiua yaey-

thony eieaeueiuie aeey eaaeaeiai auciaa aeiea e en/acatho i?e au-

oiaea ec yoiai aeiea. Noaoe/aneea ia?aiaiiua yaeythony eieaeue-

iuie, ii nio?aiytho naie cia/aiey aeey neaaeothuaai aoiaea a aeie

aeaaea iinea oiai, eae oi?aaeaiea ia?aaeaaony ca i?aaeaeu aeiea.

Aiaoiea ia?aiaiiua nouanoaotho e nio?aiytho naie cia/aiey a

oa/aiea auiieiaiey anae i?ia?aiiu e iiaoo eniieueciaaoueny aeey

nayce iaaeaeo ooieoeeyie, a oii /enea e iaaeaeo iacaaeneii neii-

ieee?iaaiiuie ooieoeeyie. ?aaeno?iaua ia?aiaiiua o?aiyony

(aee yoi aiciiaeii) a auno?uo ?aaeno?ao iaoeiu; iiaeiaii aaoi-

iaoe/aneei ia?aiaiiui iie yaeythony eieaeueiuie aeey eaaeaeiai

aeiea e en/acatho i?e auoiaea ec yoiai aeiea.

· 189 –

A ycuea “C” i?aaeoniio?aii ianeieueei iniiaiuo oeiia

iauaeoia:

iauaeou, iaienaiiua eae neiaieu (CHAR), aeinoaoi/ii aaee-

ee, /oiau o?aieoue ethaie /eai ec niioaaonoaothuaai aeaiiie ?aa-

eecaoeee aioo?aiiaai iaai?a neiaieia, e anee aeaenoaeoaeueiue

neiaie ec yoiai iaai?a neiaieia o?aieony a neiaieueiie ia?a-

iaiiie, oi aa cia/aiea yeaeaaeaioii oeaeiio eiaeo yoiai neiai-

ea. A neiaieueiuo ia?aiaiiuo iiaeii o?aieoue e ae?oaea aaee/eiu,

ii ?aaeecaoeey aoaeao iaoeiii-caaeneiie.

Iiaeii eniieueciaaoue aei o?ao ?acia?ia oeaeuo, iienuaaaiuo

eae SHORT INT, INT e LONG INT. Aeeeiiua oeaeua caieiatho ia

iaiueoa iaiyoe, /ai ei?ioeea, ii a eiie?aoiie ?aaeecaoeee ii-

aeao ieacaoueny, /oi eeai ei?ioeea oeaeua, eeai aeeeiiua oeaeua,

eeai oa e ae?oaea aoaeoo yeaeaaeaioiu i?inoui oeaeui. “I?inoua”

oeaeua eiatho anoanoaaiiue ?acia?, i?aaeoniao?eaaaiue a?oeeoae-

oo?ie eniieuecoaiie iaoeiu; ae?oaea ?acia?u aaiaeyony aeey oaeai-

eaoai?aiey niaoeeaeueiuo iio?aaiinoae.

Oeaeua aac ciaea, iienuaaaiua eae UNSIGNED, iiae/eiythony

caeiiai a?eoiaoeee ii iiaeoeth 2**N, aaea N – /enei aeoia a eo

i?aaenoaaeaiee. (Ia PDP-11 aeeeiiua aaee/eiu aac ciaea ia i?a-

aeoniio?aiu).

Ieaaathuea iaeeia?iie oi/iinoe (FLOAT) e ieaaathuea aeaieiie

oi/iinoe (DOUBLE) a iaeioi?uo ?aaeecaoeeyo iiaoo auoue neiiie-

iaie.

Iineieueeo iauaeou oiiiyioouo auoa oeiia iiaoo auoue ?a-

coiii eioa?i?aoe?iaaiu eae /enea, yoe oeiu aoaeoo iacuaaoueny

a?eoiaoe/aneeie. oeiu CHAR e INT anao ?acia?ia niaianoii ao-

aeoo iacuaaoueny oeaei/eneaiiuie. Oeiu FLOAT e DOUBLE niaianoii

aoaeoo iacuaaoueny ieaaathueie oeiaie.

E?iia iniiaiuo a?eoiaoe/aneeo oeiia nouanoaoao eiioeaioo-

aeueii aaneiia/iue eeann i?iecaiaeiuo oeiia, eioi?ua ia?acotho-

ny ec iniiaiuo oeiia neaaeothuei ia?acii:

ianneau iauaeoia aieueoeinoaa oeiia;

ooieoeee, eioi?ua aica?auatho iauaeou caaeaiiiai oeia;

oeacaoaee ia iauaeou aeaiiiai oeia;

no?oeoo?u, niaea?aeauea iineaaeiaaoaeueiinoue iauaeoia

?acee/iuo oeiia;

iauaaeeiaiey, niiniaiua niaea?aeaoue iaeei ec ianeieueeeo

iauaeoia ?acee/iuo oeiia.

Aiiaua aiai?y, yoe iaoiaeu iino?iaiey iauaeoia iiaoo i?e-

iaiyoueny ?aeo?neaii.

13. Iauaeou e L-cia/aiey

Iauaeo yaeyaony aeinooiiui ia?aaioea o/anoeii iaiyoe;

L-cia/aiea – yoi au?aaeaiea, nnueathuaany ia iauaeo. I/aaeaeiui

i?eia?ii au?aaeaiey L-cia/aiey yaeyaony eaeaioeoeeaoi?. Nouan-

oaotho iia?aoeee, ?acoeueoaoii eioi?uo yaeythony L-cia/aiey; an-

ee, iai?eia?, E – au?aaeaiea oeacaiiiai oeia, oi *E yaeyaony

au?aaeaieai L-cia/aiey, nnueathueiny ia iauaeo E. Iacaaiea

“L-cia/aiea” i?ienoiaeeo io au?aaeaiey i?enaaeaaiey E1=E2, a

eioi?ii eaaay /anoue aeieaeia auoue au?aaeaieai L-cia/aiey. I?e

iineaaeothuai ianoaeaeaiee eaaeaeie iia?aoeee aoaeao oeacuaaoueny,

iaeeaeaao ee iia iia?aiaeia L-cia/aiey e auaeaao ee iia L-cia/a-

iea.

· 190 –

14. I?aia?aciaaiey

?yae iia?aoeee iiaeao a caaeneiinoe io naieo iia?aiaeia au-

cuaaoue i?aia?aciaaiea cia/aiea iia?aiaea ec iaeiiai oeia a

ae?oaie. A yoii ?acaeaea iauyniythony ?acoeueoaou, eioi?ua nea-

aeoao iaeeaeaoue io oaeeo i?aia?aciaaiee. A i. 14.6 Iiaeaiaeyony

eoiae i?aia?aciaaiee, o?aaoaiua aieueoeinoaii iau/iuo iia?a-

oeee; yoe naaaeaiey aeiiieiythony iaiaoiaeeiui ia?acii i?e ianoae-

aeaiee eaaeaeie iia?aoeee.

14.1. Neiaieu e oeaeua

Neiaie eee ei?ioeia oeaeia iiaeii eniieueciaaoue anthaeo, aaea

iiaeii eniieueciaaoue oeaeia. Ai anao neo/ayo cia/aiea i?aia?a-

coaony e oeaeiio. I?aia?aciaaiea aieaa ei?ioeiai oeaeiai e ai-

eaa aeeeiiiio anaaaea nii?iaiaeaeaaony ciaeiaui ?anoe?aieai; oea-

eua yaeythony aaee/eiaie ni ciaeii. Inouanoaeyaony eee iao

ciaeiaia ?anoe?aiea aeey neiaieia, caaeneo io eniieuecoaiie

iaoeiu, ii aa?aioe?oaony, /oi /eai noaiaea?oiiai iaai?a nei-

aieia iaio?eoeaoaeai. ec anao iaoei, ?anniao?eaaaiuo a yoii

?oeiaiaenoaa, oieueei PDP-11 inouanoaeyao ciaeiaia ?anoe?aiea.

iaeanoue cia/aiee neiaieueiuo ia?aiaiiuo ia PDP-11 iaiyaony io

· 128 aei 127; neiaieu ec iaai?a ASC11 eiatho iieiaeeoaeueiua

cia/aiey. Neiaieueiay eiinoaioa, caaeaiiay n iiiiuueth ainueia-

?e/iie oneiaiie iineaaeiaaoaeueiinoe, iiaeaa?aaaony ciaeiaiio

?anoe?aieth e iiaeao ieacaoueny io?eoeaoaeueiie; iai?eia?, ‘377’

eiaao cia/aiea -1.

Eiaaea aieaa aeeeiiia oeaeia i?aia?acoaony a aieaa ei?ioeia

eee a CHAR, iii ia?acaaony neaaa; eeoiea aeou i?inoi ioa?a-

nuaathony.

14.2. Oeiu FLOAT e DOUBLE

Any ieaaathuay a?eoiaoeea a “C” auiieiyaony n aeaieiie

oi/iinoueth eaaeaeue ?ac, eiaaea iauaeo oeia FLOAT iiyaeyaony a

au?aaeaiee, ii oaeeeiyaony aei DOUBLE iin?aaenoaii aeiaaaeaiey

ioeae a aai ae?iaioth /anoue. eiaaea iauaeo oeia DOUBLE aeieaeai

auoue i?aia?aciaai e oeio FLOAT, iai?eia?, i?e i?enaaeaaiee,

ia?aae ona/aieai DOUBLE ie?oaeyaony aei aeeeiu FLOAT.

14.3. Ieaaathuea e oeaei/eneaiiua aaee/eiu

I?aia?aciaaiea ieaaathueo cia/aiee e oeaei/eneaiiiio oeio

eiaao oaiaeaioeeth auoue aei iaeioi?ie noaiaie iaoeiii-caaeneiui;

a /anoiinoe iai?aaeaiea ona/aiey io?eoeaoaeueiuo /enae iaiyao-

ny io iaoeia e iaoeia. ?acoeueoao ia ii?aaeaeai, anee cia/aiea

ia iiiauaaony a i?aaeinoaaeyaiia i?ino?ainoai.

I?aia?aciaaiea oeaei/eneaiiuo cia/aiee a ieaaathuea auiie-

iyaony aac ineiaeiaiee. Iiaeao i?iecieoe iaeioi?ay iioa?y oi/-

iinoe, anee aeey ?acoeueoaoa ia niaea?aeeony aeinoaoi/iiai eiee-

/anoaa aeoia.

14.4. Oeacaoaee e oeaeua

Oeaeia eee aeeeiiia oeaeia iiaeao auoue i?eaaaeaii e oeacaoa-

eth eee au/oaii ec iaai; a yoii neo/aa ia?aay aaee/eia i?aia-

?acoaony oae, eae oeacuaaaony a ?acaeaea iienaiey iia?aoeee

neiaeaiey.

· 191 –

Aeaa oeacaoaey ia iauaeou iaeeiaeiaiai oeia iiaoo auoue

au/oaiu; a yoii neo/aa ?acoeueoao i?aia?acoaony e oeaeiio, eae

oeacuaaaony a ?acaeaea iienaiey iia?aoeee au/eoaiey.

14.5. Oeaeia aac ciaea

Anyeee ?ac, eiaaea oeaeia aac ciaea iauaaeeiyaony n i?inoui

oeaeui, i?inoia oeaeia i?aia?acoaony a oeaeia aac ciaea e ?a-

coeueoao ieacuaaaony oeaeui aac ciaea. Cia/aieai yaeyaony iae-

iaiueoaa oeaeia aac ciaea, niioaaonoaothuaa oeaeiio ni ciaeii

(ii iiaeoeth 2**?acia? neiaa). A aeaie/iii aeiiieieoaeueiii i?aae-

noaaeaiee yoi i?aia?aciaaiea yaeyaony /enoi oiic?eoaeueiui e

ia eciaiyao oaeoe/aneoth eiiaeiaoeeth aeoia.

Eiaaea oeaeia aac ciaea i?aia?acoaony e oeio LONG, cia/a-

iea ?acoeueoaoa niaiaaeaao ni cia/aieai oeaeiai aac ciaea. Oa-

eei ia?acii, yoi i?aia?aciaaiea naiaeeony e aeiaaaeaieth ioeae

neaaa.

14.6. A?eoiaoe/aneea i?aia?aciaaiey

Iiaeaaeythuaa aieueoeinoai iia?aoeee aucuaaao i?aia?aciaaiea

e ii?aaeaeyao oeiu ?acoeueoaoa aiaeiae/iui ia?acii. I?eaiaeeiay

ieaea noaia a aeaeueiaeoai aoaeao iacuaaoueny “iau/iuie a?eoiaoe-

/aneeie i?aia?aciaaieyie”.

Nia/aea ethaua iia?aiaeu oeia CHAR eee SHORT i?aia?acothony a

INT, a ethaua iia?aiaeu oeia FLOAT i?aia?acothony a DOUBLE.

Caoai, anee eaeie-eeai iia?aiae eiaao oei DOUBLE, oi ae?oaie

i?aia?acoaony e oeio DOUBLE, e yoi aoaeao oeiii ?acoeueoaoa.

A i?ioeaiii neo/aa, anee eaeie-eeai iia?aiae eiaao oei LONG,

oi ae?oaie iia?aiae i?aia?acoaony e oeio LONG, e yoi e aoaeao

oeiii ?acoeueoaoa.

A i?ioeaiii neo/aa, anee eaeie-eeai iia?aiae eiaao oei

UNSIGNED, oi ae?oaie iia?aiae i?aia?acoaony e oeio UNSIGNED,

e yoi aoaeao oeiii ?acoeueoaoa.

A i?ioeaiii neo/aa iaa iia?aiaea aoaeoo eiaoue oei INT, e yoi

aoaeao oeiii ?acoeueoaoa.

15. Au?aaeaiey

Noa?oeinoai iia?aoeee a au?aaeaieyo niaiaaeaao n ii?yaeeii

neaaeiaaiey iniiaiuo iiae?acaeaeia ianoiyuaai ?acaeaea, ia/eiay

n naiiai aunieiai o?iaiy noa?oeinoaa. Oae, iai?eia?, au?aaea-

ieyie, oeacuaaaiuie a ea/anoaa iia?aiaeia iia?aoeee +

(i.15.4), ssaeythony au?aaeaiey, ii?aaeaeaiiua a i.i.15.1-15.3.

Aioo?e eaaeaeiai iiae?acaeaea iia?aoeee eiaao iaeeiaeiaia noa?oei-

noai. A eaaeaeii iiae?acaeaea aeey iienuaaaiuo oai iia?aoeee oea-

cuaaaony eo annioeeaoeaiinoue neaaa eee ni?aaa. Noa?oeinoai e

annioeeaoeaiinoue anao iia?aoeee a au?aaeaieyo ?acthie?othony a

a?aiiaoe/aneie naiaeea a i.18.

A i?ioeaiii neo/aa ii?yaeie au/eneaiee au?aaeaiee ia ii?a-

aeaeai. A /anoiinoe, eiiieeyoi? n/eoaao naay a i?aaa au/en-

eyoue iiaeau?aaeaiey a oii ii?yaeea, eioi?ue ii iaoiaeeo iaeaieaa

yooaeoeaiui, aeaaea anee yoe iiaeau?aaeaiey i?eaiaeyo e iiai/iui

yooaeoai. Ii?yaeie, a eioi?ii i?ienoiaeyo iiai/iua yooaeou, ia

niaoeeoeoee?oaony. Au?aaeaiey, aeeth/athuea eiiiooaoeaiua e anni-

oeeaoeaiua iia?aoeee ( *,+,&,!,^ ), iiaoo auoue ia?aoii?yaei/aiu

i?iecaieueiui ia?acii aeaaea i?e iaee/ee e?oaeuo neiaie; /oiau

auioaeeoue ii?aaeaeaiiue ii?yaeie au/eneaiee, a yoii neo/aa ia-

iaoiaeeii eniieueciaaoue yaiua i?iiaaeooi/iua ia?aiaiiua.

· 192 –

I?e au/eneaiee au?aaeaiee ia?aaioea ia?aiieiaiey e i?i-

aa?ea i?e aeaeaiee yaeythony iaoeiii-caaeneiuie. Ana nouanoao-

thuea ?aaeecaoeee ycuea “C” eaii?e?otho ia?aiieiaiea oeaeuo; ia-

?aaioea neooaoeee i?e aeaeaiee ia 0 e i?e anao iniauo neo/ayo

n ieaaathueie /eneaie iaiyaony io iaoeiu e iaoeia e iau/ii

auiieiyaony n iiiiuueth aeaeeioa/iie ooieoeee.

15.1. Ia?ae/iua au?aaeaiey

Ia?ae/iua au?aaeaiey, aeeth/athuea ., ->, eiaeaenaoeeth e ia-

?auaiey e ooieoeeyi, a?oiie?othony neaaa iai?aai.

Ia?ae/iia au?aaeaiea:

eaeaioeoeeaoi?

eiinoaioa

no?iea

(au?aaeaiea)

ia?ae/iia-au?aaeaiea [au?aaeaiea]

ia?ae/iia-au?aaeaiea (nienie-au?aaeaiee iai

ia?ae/iia-L-cia/aiea . Eaeaioeoeeaoi?

ia?ae/iia-au?aaeaiea -> eaeaioeoeeaoi?

nienie-au?aaeaiee:

au?aaeaiea

nienie-au?aaeaiee, au?aaeaiea

Eaeaioeoeeaoi? yaeyaony ia?ae/iui au?aaeaieai i?e oneiaee, /oi

ii iienai iiaeoiaeyuei ia?acii, eae yoi ianoaeaeaaony ieaea. oei

eaeaioeoeeaoi?a ii?aaeaeyaony aai iienaieai. Anee, iaeiaei, oe-

iii eaeaioeoeeaoi?a yaeyaony “iannea …”, oi cia/aieai au?a-

aeaiey, ninoiyuaai ec yoiai eaeaioeoeeaoi?a , yaeyaony oeaca-

oaeue ia ia?aue iauaeo a yoii ianneaa, a oeiii au?aaeaiey ao-

aeao “oeacaoaeue ia …”. Aieaa oiai, eaeaioeoeeaoi? ianneaa ia

yaeyaony au?aaeaieai L-cia/aiey. iiaeiaiui ia?acii eaeaioeoeea-

oi?, eioi?ue iienai eae “ooieoeey, aica?auathuay …”, ca ene-

eth/aieai oiai neo/ay, eiaaea ii eniieuecoaony a iiceoeee eiaie

ooieoeee i?e ia?auaiee, i?aia?acoaony a “oeacaoaeue ia ooie-

oeeth, eioi?ay aica?auaao …”.

Eiinoaioa yaeyaony ia?ae/iui au?aaeaieai. A caaeneiinoe

io aa oi?iu oeiii eiinoaiou iiaeao auoue INT, LONG eee DOUBLE.

No?iea yaeyaony ia?ae/iui au?aaeaieai. Enoiaeiui aa oeiii

yaeyaony “iannea neiaieia”; ii neaaeoy oai aea naiui i?aaeeai,

eioi?ua i?eaaaeaiu auoa aeey eaeaioeoeeaoi?ia, ii iiaeeoeoee?oao-

ny a “oeacaoaeue ia neiaieu”, e ?acoeueoaoii yaeyaony oeaca-

oaeue ia ia?aue neiaie no?iee. (eiaaony eneeth/aiea a iaeioi-

?uo eieoeeaeecaoi?ao; ni. I. 16.6.)

Au?aaeaiea a e?oaeuo neiaeao yaeyaony ia?ae/iui au?aaeaie-

ai, oei e cia/aiea eioi?iai eaeaioe/iu oeio e cia/aieth yoiai

au?aaeaiey aac neiaie. Iaee/ea e?oaeuo neiaie ia aeeyao ia

oi, yaeyaony ee au?aaeaiea L-cia/aieai eee iao.

· 193 –

Ia?ae/iia au?aaeaiea, ca eioi?ui neaaeoao au?aaeaiea a

eaaae?aoiuo neiaeao, yaeyaony ia?ae/iui au?aaeaieai. Eiooeoea-

ii ynii, /oi yoi au?aaeaiea n eiaeaenii. Iau/ii ia?ae/iia au-

?aaeaiea eiaao oei “oeacaoaeue ia …”, eiaeaeniia au?aaeaiea

eiaao oei INT, a oeiii ?acoeueoaoa yaeyaony “…”. Au?aaeaiea

E1[E2] ii ii?aaeaeaieth eaeaioe/ii au?aaeaieth * ((E1) + (E2)).

Ana, /oi iaiaoiaeeii aeey iiieiaiey yoie caiene, niaea?aeeony a

yoii ?acaeaea; aii?inu, naycaiiua n iiiyoeai eaeaioeoeeaoi?ia

e iia?aoeee * e + ?anniao?eaathony a i.i. 15.1, 15.2 E 15.4

niioaaonoaaiii; auaiaeu noiie?othony ieaea a i. 22.3.

Ia?auaiea e ooieoeee yaeyaony ia?ae/iui au?aaeaieai, ca

eioi?ui neaaeoao caeeth/aiiue a e?oaeua neiaee aiciiaeii ionoie

nienie au?aaeaiee, ?acaeaeaiiuo caiyouie, eioi?ua e i?aaenoaa-

eytho niaie oaeoe/aneea a?aoiaiou ooieoeee. Ia?ae/iia au?aaea-

iea aeieaeii auoue oeia “ooieoeey, aica?auathuay …”, a ?acoeue-

oao ia?auaiey e ooieoeee eiaao oei “…”. Eae oeacuaaaony ie-

aea, ?aiaa ia ano?a/aaueeny eaeaioeoeeaoi?, ca eioi?ui iaiin-

?aaenoaaiii neaaeoao eaaay e?oaeay neiaea, n/eoaaony iienaiiui

ii eiioaenoo, eae i?aaenoaaeythuee ooieoeeth, aica?auathuoth oea-

eia; neaaeiaaoaeueii /aua anaai ano?a/athueeny neo/ae ooieoeee,

aica?auathuae oeaeia cia/aiea, ia ioaeaeaaony a iienaiee.

Ia?aae ia?auaieai ethaua oaeoe/aneea a?aoiaiou oeia FLOAT

i?aia?acothony e oeio DOUBLE, ethaua a?aoiaiou oeia CHAR eee

SHORT i?aia?acothony e oeio INT, e, eae iau/ii, eiaia ianne-

aia i?aia?acothony a oeacaoaee. Ieeaeea ae?oaea i?aia?aciaaiey

ia auiieiythony aaoiiaoe/anee; a /anoiinoe, ia n?aaieaaao oe-

iu oaeoe/aneeo a?aoiaioia n oeiaie oi?iaeueiuo a?aoiaioia.

Anee i?aia?aciaaiea iaiaoiaeeii, eniieuecoeoa yaiue ia?aaiae

oeia (CAST); ni. I.i. 15.2, 16.7.

I?e iiaeaioiaea e auciao ooieoeee aeaeaaony eiiey eaaeaeiai

oaeoe/aneiai ia?aiao?a; oaeei ia?acii, ana ia?aaea/e a?aoiai-

oia a ycuea “C” inouanoaeythony no?iai ii cia/aieth. ooieoeey

iiaeao eciaiyoue cia/aiey naieo oi?iaeueiuo ia?aiao?ia, ii yoe

eciaiaiey ia aeeytho ia cia/aiey oaeoe/aneeo ia?aiao?ia. N

ae?oaie no?iiu eiaaony aiciiaeiinoue ia?aaeaaaoue oeacaoaeue i?e

oaeii oneiaee, /oi ooieoeey iiaeao eciaiyoue cia/aiea iauaeoa,

ia eioi?ue yoio oeacaoaeue oeacuaaao. Ii?yaeie au/eneaiey a?-

aoiaioia a ycuea ia ii?aaeaeai; ia?aoeoa aieiaiea ia oi, /oi

?acee/iua eiiieeyoi?u au/eneytho ii ?aciiio.

Aeiioneathony ?aeo?neaiua ia?auaiey e ethaie ooieoeee.

Ia?ae/iia au?aaeaiea, ca eioi?ui neaaeoao oi/ea e eaeaioe-

oeeaoi?, yaeyaony au?aaeaieai. Ia?aia au?aaeaiea aeieaeii auoue

L-cia/aieai, eiaiothuei no?oeoo?o eee iauaaeeiaiea, a eaeaioe-

oeeaoi? aeieaeai auoue eiaiai /eaia no?oeoo?u eee iauaaeeiaiey.

?acoeueoaoii yaeyaony L-cia/aiea, nnueathuaany ia iieiaiiaai-

iue /eai no?oeoo?u eee iauaaeeiaiey.

Ia?ae/iia au?aaeaiea, ca eioi?ui neaaeoao no?aeea (ninoaa-

eaiiay ec ciaeia – e >) e eaeaioeoeeaoi?, yaeyaony au?aaeaie-

ai. ia?aia au?aaeaiea aeieaeii auoue oeacaoaeai ia no?oeoo?o eee

iauaaeeiaiea, a eaeaioeoeeaoi? aeieaeai eiaiiaaoue /eai yoie

no?oeoo?u eee iauaaeeiaiey. ?acoeueoaoii yaeyaony L-cia/aiea,

nnueathuaany ia iieiaiiaaiiue /eai no?oeoo?u eee iauaaeeiaiey,

ia eioi?ue oeacuaaao oeacaoaeueiia au?aaeaiea.

Neaaeiaaoaeueii, au?aaeaiea E1->MOS yaeyaony oai aea naiui,

/oi e au?aaeaiea (*E1).MOS. No?oeoo?u e iauaaeeiaiey ?anniao-

?eaathony a i. 16.5. I?eaaaeaiiua caeanue i?aaeea eniieueciaaiey

no?oeoo? e iauaaeeiaiee ia iaaycuaathony no?iai, aeey oiai /oi-

au eiaoue aiciiaeiinoue iaieoe iaoaieci oeiia. Ni. I. 22.1.

· 194 –

15.2. Oia?iua iia?aoeee

Au?aaeaiea n oia?iuie iia?aoeeyie a?oiie?oaony ni?aai ia-

eaai.

Oia?iia-au?aaeaiea:

· au?aaeaiea

& L-cia/aiea

· au?aaeaiea

! Au?aaeaiea

^ au?aaeaiea

++ L-cia/aiea

· L-cia/aiea

L-cia/aiea ++

L-cia/aiea—

(eiy-oeia) au?aaeaiea

SIZEOF au?aaeaiea

SIZEOF eiy-oeia

Oia?iay iia?aoeey * icia/aao einaaiioth aae?anaoeeth: au?aaea-

iea aeieaeii auoue oeacaoaeai, a ?acoeueoaoii yaeyaony L-cia/a-

iea, nnueathuaany ia oio iauaeo, ia eioi?ue oeacuaaao au?aaea-

iea. Anee oeiii au?aaeaiey yaeyaony “oeacaoaeue ia…”, oi oe-

iii ?acoeueoaoa aoaeao “…”.

?acoeueoaoii oia?iie iia?aoeee & yaeyaony oeacaoaeue ia

iauaeo, e eioi?iio nnueaaony L-cia/aiea. Anee L-cia/aiea

eiaao oei “…”, oi oeiii ?acoeueoaoa aoaeao “oeacaoaeue ia

…”.

?acoeueoaoii oia?iie iia?aoeee – (ieion) yaeyaony aa iia-

?aiae, acyoue n i?ioeaiiieiaeiui ciaeii. Aeey aaee/eiu oeia

UNSIGNED ?acoeueoao iieo/aaony au/eoaieai aa cia/aiey ec 2**N

(aeaa a noaiaie N), aaea N-/enei aeoia a INT. Oia?iie iia?aoeee

+ (iethn) ia nouanoaoao.

?acoeueoaoii iia?aoeee eiae/aneiai io?eoeaiey ! ssaeyaony 1,

anee cia/aiea aa iia?aiaea ?aaii 0, e 0, anee cia/aiea aa

iia?aiaea ioee/ii io ioey. ?acoeueoao eiaao oei INT. Yoa iia-

?aoeey i?eiaieia e ethaiio a?eoiaoe/aneiio oeio eee oeacaoa-

eyi.

Iia?aoeey ^ aeaao ia?aoiue eiae, eee aeiiieiaiea aei aaeeie-

oeu, naiaai iia?aiaea. Auiieiythony iau/iua a?eoiaoe/aneea i?a-

ia?aciaaiey. Iia?aiae aeieaeai auoue oeaei/eneaiiiai oeia.

Iauaeo, ia eioi?ue nnueaaony iia?aiae L-cia/aiey i?aoeen-

iie iia?aoeee ++, oaaee/eaaaony. cia/aieai yaeyaony iiaia

cia/aiea iia?aiaea, ii yoi ia L-cia/aiea. Au?aaeaiea ++o yeae-

aaeaioii o+=1. Eioi?iaoeeth i i?aia?aciaaieyo niio?e a ?acai?a

iia?aoeee neiaeaiey (i. 15.4) e iia?aoeee i?enaaeaaiey (i.

15.14).

I?aoeeniay iia?aoeey—aiaeiae/ia i?aoeeniie iia?aoeee

++, ii i?eaiaeeo e oiaiueoaieth naiaai iia?aiaea L-cia/aiey.

I?e i?eiaiaiee iinooeeniie iia?aoeee ++ e L-cia/aieth ?a-

coeueoaoii yaeyaony cia/aiea iauaeoa, ia eioi?ue nnueaaony

L-cia/aiea. Iinea oiai, eae ?acoeueoao i?eiyo e naaaeaieth,

iauaeo oaaee/eaaaony oi/ii oaeei aea ia?acii, eae e a neo/aa

i?aoeeniie iia?aoeee ++. ?acoeueoao eiaao oio aea oei, /oi e

au?aaeaiea L-cia/aiey.

· 195 –

I?e i?eiaiaiee iinooeeniie iia?aoeee—e L-cia/aieth ?a-

coeueoaoii yaeyaony cia/aiea iauaeoa, ia eioi?ue nnueaaony

L-cia/aiea. Iinea oiai, eae ?acoeueoao i?eiyo e naaaeaieth,

iauaeo oiaiueoaaony oi/ii oaeei aea ia?acii, eae e a neo/aa

i?aoeeniie iia?aoeee –. ?acoeueoao eiaao oio aea oei, /oi e

au?aaeaiea L-cia/aiey.

Caeeth/aiiia a e?oaeua neiaee eiy oeia aeaiiuo,noiyuaa ia-

?aae au?aaeaieai , aucuaaao i?aia?aciaaiea cia/aiey yoiai au-

?aaeaiey e oeacaiiiio oeio. Yoa eiino?oeoeey iacuaaaony ia?a-

aiae (CAST). Eiaia oeiia iienuaathony a i. 16.7.

Iia?aoeey SIZEOF auaeaao ?acia? naiaai iia?aiaea a aaeoao.

(Iiiyoea aaeo a ycuea ia ii?aaeaeaii, ?acaa oieueei eae cia/a-

iea iia?aoeee SIZEOF. Iaeiaei ai anao nouanoaothueo ?aaeecaoeeyo

aaeoii yaeyaony i?ino?ainoai, iaiaoiaeeiia aeey o?aiaiey

iauaeoa oeia CHAR). I?e i?eiaiaiee e ianneao ?acoeueoaoii ya-

eyaony iieiia /enei aaeoia a ianneaa. ?acia? ii?aaeaeyaony ec

iienaiee iauaeoia a au?aaeaiee. Yoi au?aaeaiea naiaioe/anee

yaeyaony oeaeie eiinoaioie e iiaeao auoue eniieueciaaii a ethaii

ianoa, aaea o?aaoaony eiinoaioa. Iniiaiia i?eiaiaiea yoa iia-

?aoeey iaoiaeeo i?e naycyo n i?ioeaaeo?aie, iiaeiaiui ?ani?aaeaee-

oaeyi iaiyoe, e a nenoaiao aaiaea- auaiaea.

Iia?aoeey SIZEOF iiaeao auoue oaeaea i?eiaiaia e e caeeth/ai-

iiio a e?oaeua neiaee eiaie oeia. A yoii neo/aa iia auaeaao

?acia? a aaeoao iauaeoa oeacaiiiai oeia.

Eiino?oeoeey SIZEOF (oei) ?anniao?eaaaony eae oeaeia, oae

/oi au?aaeaiea SIZEOF (oei) – 2 yeaeaaeaioii au?aaeaieth

(SIZEOF (oei)9 – 2.

15.3. Ioeueoeieeeaoeaiua iia?aoeee

Ioeueoeieeeaoeaiua iia?aoeee *, /, e % a?oiie?othony neaaa

iai?aai. Auiieiythony iau/iua a?eoiaoe/aneea i?aia?aciaaiey.

Ioeueoeieeeaoeaiia-au?aaeaiea:

au?aaeaiea * au?aaeaiea

au?aaeaiea / au?aaeaiea

au?aaeaiea % au?aaeaiea

Aeia?iay iia?aoeey * icia/aao oiiiaeaiea. Iia?aoeey * anni-

oeeaoeaia, e au?aaeaiey n ianeieueeeie oiiiaeaieyie ia iaeiii e

oii aea o?iaia iiaoo auoue ia?aa?oiie?iaaiu eiiieeyoi?ii.

Aeia?iay iia?aoeey / icia/aao aeaeaiea. I?e aeaeaiee iiei-

aeeoaeueiuo oeaeuo inouanoaeyaony ona/aiea ii iai?aaeaieth e io-

eth, ii anee iaeei ec iia?aiaeia io?eoeaoaeai, oi oi?ia ona/aiey

caaeneo io eniieuecoaiie iaoeiu. Ia anao iaoeiao, ioaaouaaa-

iuo ianoiyuei ?oeiaiaenoaii, inoaoie eiaao oio aea ciae , /oi

e aeaeeiia. Anaaaea ni?aaaaeeeai, /oi (A/B)*B+A%B ?aaii A (anee

B ia ?aaii 0).

Aeia?iay iia?aoeey % auaeaao inoaoie io aeaeaiey ia?aiai

au?aaeaiey ia aoi?ia. Auiieiythony iau/iua a?eoiaoe/aneea i?a-

ia?aciaaiey. Iia?aiaeu ia aeieaeiu auoue oeia FLOAT.

15.4. Aaeaeeoeaiua iia?aoeee

Aaeaeeoeaiua iia?aoeee + e – a?oiie?othony neaaa iai?aai.

auiieiythony iau/iua a?eoiaoe/aneea i?aia?aciaaiey. Aeey eaae-

aeie iia?aoeee eiathony iaeioi?ua aeiiieieoaeueiua aiciiaeiinoe,

naycaiiua n oeiaie iia?aiaeia.

· 196 –

Aaeaeeoeaiia-au?aaeaiea:

au?aaeaiea + au?aaeaiea

au?aaeaiea – au?aaeaiea

?acoeueoaoii iia?aoeee + yaeyaony noiia iia?aiaeia. Iiaeii neea-

aeuaaoue oeacaoaeue ia iauaeo a ianneaa e cia/aiea ethaiai oeaei-

/eneaiiiai oeia. ai anao neo/ayo iineaaeiaa i?aia?acoaony a

aae?aniia niauaiea iin?aaenoaii oiiiaeaiey aai ia aeeeio iauae-

oa, ia eioi?ue oeacuaaao yoio oeacaoaeue. ?acoeueoaoii yaeyao-

ny oeacaoaeue oiai aea naiiai oeia, /oi e enoiaeiue oeacaoaeue,

eioi?ue oeacuaaao ia ae?oaie iauaeo a oii aea ianneaa, niauai-

iue niioaaonoaothuei ia?acii ioiineoaeueii ia?aiia/aeueiiai

iauaeoa. Oaeei ia?acii, anee P yaeyaony oeacaoaeai iauaeoa a

ianneaa, oi au?aaeaiea P+1 yaeyaony oeacaoaeai ia neaaeothuee

iauaeo a yoii ianneaa.

Ieeaeea ae?oaea eiiaeiaoeee oeiia aeey oeacaoaeae ia ?ac?a-

oathony.

Iia?aoeey + annioeeaoeaia, e au?aaeaiea n ianeieueeeie nei-

aeaieyie ia oii aea naiii o?iaia iiaoo auoue ia?aoii?yaei/aiu

eiiieeyoi?ii.

?acoeueoaoii iia?aoeee – yaeyaony ?aciinoue iia?aiaeia. Au-

iieiythony iau/iua a?eoiaoe/aneea i?aia?aciaaiey. E?iia oiai,

ec oeacaoaey iiaeao auoue au/oaii cia/aiea ethaiai oeaei/eneai-

iiai oeia, i?e/ai, i?iaiaeyony oa aea naiua i?aia?aciaaiey,

/oi e i?e iia?aoeee neiaeaiey.

Anee au/eoathony aeaa oeacaoaey ia iauaeou iaeeiaeiaiai oe-

ia, oi ?acoeueoao i?aia?acoaony (aeaeaieai ia aeeeio iauaeoa) e

oeio INT, i?aaenoaaeyy niaie /enei iauaeoia, ?acaeaeythueo oea-

cuaaaiua iauaeou. Anee yoe oeacaoaee ia ia iauaeou ec iaeiiai

e oiai aea ianneaa, oi oaeia i?aia?aciaaiea, aiiaua aiai?y,

aeano iaiaeeaeaiiua ?acoeueoaou, iioiio /oi aeaaea oeacaoaee ia

iauaeou iaeeiaeiaiai oeia ia iaycaiu ioee/aoueny ia aaee/eio,

e?aoioth aeeeia iauaeoa.

15.5. Iia?aoeee naeaeaa

Iia?aoeee naeaeaa > a?oiie?othony neaaa iai?aai. Aeey

iaaeo iia?aoeee i?iaiaeyony iau/iua a?eoiaoe/aneea i?aia?aci-

aaiey eo iia?aiaeia, eaaeaeue ec eioi?uo aeieaeai auoue oeaei/en-

eaiiiai oeia. Caoai i?aaue iia?aiae i?aia?acoaony e oeio INT;

?acoeueoao eiaao oei eaaiai iia?aiaea. ?acoeueoao ia ii?aaeaeai,

anee i?aaue iia?aiae io?eoeaoaeai eee aieueoa eee ?aaai, /ai

aeeeia iauaeoa a aeoao.

Au?aaeaiea-naeaeaa:

au?aaeaiea > au?aaeaiea

Cia/aieai au?aaeaiey E1>E2 ya-

eyaony E1, naeaeiooia ai?aai ia E2 aeoiauo iiceoeee. Anee E1

eiaao oei UNSIGNE, oi naeaea ai?aai aa?aioe?iaaiii aoaeao ei-

ae/aneei (caiieiaiea ioeai); a i?ioeaiii neo/aa naeaea iiaeao

auoue (e oae e anoue ia PDP-11) a?eoiaoe/aneei (inaiaiaeaeathuea-

ny aeou caiieiythony eiieae ciaeiaiai aeoa).

· 197 –

15.6. Iia?aoeee ioiioaiey

Iia?aoeee ioiioaiey a?oiie?othony neaaa iai?aai, ii yoio

oaeo ia i/aiue iieacai; au?aaeaiea A au?aaeaiea

au?aaeaiea = au?aaeaiea

Iia?aoeee (aieueoa), =

(aieueoa eee ?aaii) ana aeatho 0, anee oeacaiiia ioiioaiea eiae-

ii, e 1, anee iii enoeiii. ?acoeueoao eiaao oei ITN. Auiieiy-

thony iau/iua a?eoiaoe/aneea i?aia?aciaaiey. Iiaoo n?aaie-

aaoueny aeaa oeacaoaey; ?acoeueoao caaeneo io ioiineoaeueiiai

?aniieiaeaiey oeacuaaaiuo iauaeoia a aae?aniii i?ino?ainoaa.

N?aaiaiea oeacaoaeae ia?aiineii oieueei a oii neo/aa, anee

oeacaoaee oeacuaatho ia iauaeou ec iaeiiai e oiai aea ianneaa.

15.7. Iia?aoeee ?aaainoaa Au?aaeaiea-?aaainoaa:

au?aaeaiea == au?aaeaiea

au?aaeaiea != au?aaeaiea

Iia?aoeee == (?aaii) e != (ia ?aaii) a oi/iinoe aiaeiae/iu

iia?aoeeyi ioiioaiey, ca eneeth/aieai oiai, /oi iie eiatho ai-

eaa ieceee o?iaaiue noa?oeinoaa. (Iiyoiio cia/aiea au?aaeaiey

A>= au?aaeaiea

L-cia/aiea COUNT

nnueaaony e iieth COUNT no?oeoo?u, ia eioi?oth oeacuaaao SP;

au?aaeaiea

S.LEFT

nnueaaony ia oeacaoaeue eaaiai iiaeaea?aaa a no?oeoo?a S, a au-

?aaeaiea

S.RIGHT->TWORD[0]

nnueaaony ia ia?aue neiaie /eaia TWORD i?aaiai iiaeaea?aaa ec

S.

· 207 –

16.6. Eieoeeaeecaoeey

Iienaoaeue iiaeao oeacuaaoue ia/aeueiia cia/aiea iienuaaaii-

ai eaeaioeoeeaoi?a. Eieoeeaeecaoi? ninoieo ec au?aaeaiey eee

caeeth/aiiiai a oeao?iua neiaee nienea cia/aiee, ia?aae eioi-

?uie noaaeony ciae =.

Eieoeeaeecaoi?:

= au?aaeaiea

= (nienie-eieoeeaeecaoi?a)

= (nienie-eieoeeaeecaoi?a,)

nienie-eieoeeaeecaoi?a:

au?aaeaiea

nienie-eieoeeaeecaoi?a,nienie-eieoeeaeecaoi?a

(nienie-eieoeeaeecaoi?a)

Ana au?aaeaiey, aoiaeyuea a eieoeeaeecaoi? noaoe/aneie eee

aiaoiae ia?aiaiiie, aeieaeiu auoue eeai eiinoaioiuie au?aaeaiey-

ie, iienuaaaiuie a i. 23, Eeai au?aaeaieyie, eioi?ua naiaeyony

e aae?ano ?aiaa iienaiiie ia?aiaiiie, aiciiaeii niauaiiiio ia

eiinoaioiia au?aaeaiea. Aaoiiaoe/aneea e ?aaeno?iaua ia?aiai-

iua iiaoo auoue eieoeeaeece?iaaiu i?iecaieueiuie au?aaeaieyie,

aeeth/athueie eiinoaiou e ?aiaa iienaiiua ia?aiaiiua e ooie-

oeee.

Aa?aioe?oaony, /oi iaeieoeeaeece?iaaiiua noaoe/aneea e

aiaoiea ia?aiaiiua iieo/atho a ea/anoaa ia/aeueiuo cia/aiee

0;iaeieoeeaeece?iaaiiua aaoiiaoe/aneea e ?aaeno?iaua ia?aiai-

iua a ea/anoaa ia/aeueiuo cia/aiee niaea?aeao ioni?.

Eiaaea eieoeeaeecaoi? i?eiaiyaony e neaey?o (oeacaoaeth eee

iauaeoo a?eoiaoe/aneiai oeia), oi ii ninoieo ec iaeiiai au?a-

aeaiey, aiciiaeii caeeth/aiiiai a oeao?iua neiaee. Ia/aeueiia

cia/aiea iauaeoa iaoiaeeony ec au?aaeaiey; auiieiythony oa aea

naiua i?aia?aciaaiey, /oi e i?e i?enaaeaaiee.

Eiaaea iienuaaaiay ia?aiaiiay yaeyaony aa?aaaoii (no?oe-

oo?ie eee ianneaii ), oi eieoeeaeecaoi? ninoieo ec caeeth/ai-

iiai a oeao?iua neiaee e ?acaeaeaiiiai caiyouie nienea eieoee-

aeecaoi?ia aeey /eaiia aa?aaaoa. Yoio nienie ninoaaeyaony a

ii?yaeea aic?anoaiey eiaeaena eee a niioaaonoaee n ii?yaeeii

/eaiia. Anee aa?aaao niaea?aeeo iiaeaa?aaaou, oi yoi i?aaeei

i?eiaiyaony ?aeo?neaii e /eaiai aa?aaaoa. Anee eiee/anoai

eieoeeaeecaoi?ia a nienea ieacuaaaony iaiueoa /enea /eaiia aa-

?aaaoa, oi inoaaoeany /eaiu aa?aaaoa caiieiythony ioeyie.

Cai?auaaony eieoeeaeece?iaaoue iauaaeeiaiey eee aaoiiaoe/aneea

aa?aaaou.

Oeao?iua neiaee iiaoo auoue iiouaiu neaaeothuei ia?acii.

Anee eieoeeaeecaoi? ia/eiaaony n eaaie oeao?iie neiaee, oi

iineaaeothuee ?acaeaeaiiue caiyouie nienie eieoeeaeecaoi?ia eie-

oeeaeece?oao /eaiu aa?aaaoa; aoaeao ioeaeie, anee a nienea

ieaaeaony aieueoa eieoeeaeecaoi?ia, /ai /eaiia aa?aaaoa. Anee

iaeiaei eieoeeaeecaoi? ia ia/eiaaony n eaaie oeao?iie neiaee,

oi ec nienea aa?aony oieueei ioaeiia aeey /eaiia aeaiiiai aa?a-

aaoa /enei yeaiaioia; inoaaoeany yeaiaiou eniieuecothony aeey

eieoeeaeecaoeee neaaeothuaai /eaia aa?aaaoa, /anoueth eioi?iai ya-

eyaony ianoiyuee aa?aaao.

· 208 –

Iineaaeiaa nie?auaiea aeiioneaao aiciiaeiinoue eieoeeaeecaoeee

ianneaa oeia CHAR n iiiiuueth no?iee. A yoii neo/aa /eaiu ian-

neaa iineaaeiaaoaeueii eieoeeaeece?othony neiaieaie no?iee.

Iai?eia?,

INT X[] = (1,3,5);

iienuaaao e eieoeeaeece?oao X eae iaeiiia?iue iannea; iineieue-

eo ?acia? ianneaa ia niaoeeoeoee?iaai, a nienie eieoeeaeeceoi?a

niaea?aeeo o?e yeaiaioa, n/eoaaony, /oi iannea ninoieo ec o?ao

/eaiia.

Aio i?eia? eieoeeaeecaoeee n iieiui eniieueciaaieai oeao?-

iuo neiaie:

FLOAT *Y[4][3] = (

( 1, 3, 5 ),

( 2, 4, 6 ),

( 3, 5, 7 ),

);

Caeanue 1, 3 e 5 eieoeeaeece?otho ia?aoth no?ieo ianneaa Y[0], a

eiaiii Y[0][0], Y[0][1] e Y[0][2]. Aiaeiae/iui ia?acii nea-

aeothuea aeaa no?i/ee eieoeeaeece?otho Y[1] e Y[2]. Eieoeeaeecaoi?

caeai/eaaaony i?aaeaeaa?aiaiii, e, neaaeiaaoaeueii iannea Y[3]

eieoeeaeece?oaony ioeyie. A oi/iinoe oaeiai aea yooaeoa iiaeii

auei au aeinoe/ue, iaienaa

FLOAT Y[4][3] = (

1, 3, 5, 2, 4, 6, 3, 5, 7

);

Eieoeeaeecaoi? aeey Y ia/eiaaony n eaaie oeao?iie neiaee, ii

eieoeeaeecaoi?a aeey Y[0] iao. Iiyoiio eniieuecoaony 3 yeaiaioa

ec nienea. Aiaeiae/ii neaaeothuea o?e yeaiaioa eniieuecothony

iineaaeiaaoaeueii aeey Y[1] e Y[2]. neaaeothuaa iienaiea

FLOAT Y[4][3] = (

(1), (2), (3), (4)

);

eieoeeaeece?oao ia?aue noieaaoe Y (anee aai ?anniao?eaaoue eae

aeaoia?iue iannea), a inoaeueiua yeaiaiou caiieiythony ioeyie.

E iaeiiaoe, iienaiea

CHAR MSG[] = “SYNTAX ERROR ON LINE %SN”;

aeaiiino?e?oao eieoeeaeecaoeeth yeaiaioia neiaieueiiai ianneaa n

iiiiuueth no?iee.

16.7. Eiaia oeiia

A aeaoo neo/ayo (aeey yaiiai oeacaiey oeia i?aia?aciaaiey

a eiino?oeoeee ia?aaiaea e aeey a?aoiaioia iia?aoeee SIZEOF) aea-

eaoaeueii eiaoue aiciiaeiinoue caaeaaaoue eiy oeia aeaiiuo. Yoi

inouanoaeyaony n iiiiuueth “eiaie oeia”, eioi?ia ii nouanoao

yaeyaony iienaieai iauaeoa oaeiai oeia , a eioi?ii iiouaii

eiy naiiai iauaeoa.

· 209 –

Eiy oeia:

niaoeeoeeaoi?-oeia aano?aeoiue-iienaoaeue

aano?aeoiue-iienaoaeue:

ionoi

(aano?aeoiue-iienaoaeue)

· aano?aeoiue iienaoaeue aano?aeoiue-iienaoaeue ()
aano?aeoiue-iienaoaeue [eiinoaioiia au?aaeaiea

iaia]

Ai ecaaaeaiee aeaoniuneaiiinoe a eiino?oeoeee

(aano?aeoiue iienaoaeue)

o?aaoaony, /oiau aano?aeoiue-iienaoaeue aue iaiono. I?e yoii

ia?aie/aiee aiciiaeii iaeiicia/aii ii?aaeaeeoue oi ianoi a aano-

?aeoiii-iienaoaea, aaea au iiyaeeny eaeaioeoeeaoi?, anee au

yoa eiino?oeoeey auea iienaoaeai a iienaiee. Eiaiiaaiiue oei

niaiaaeaao oiaaea n oeiii aeiioaoe/aneiai eaeaioeoeeaoi?a. Iai-

?eia?, eiaia oeiia

INT

INT *

INT *[3]

INT (*)[3]

INT *()

INT (*)()

eiaiotho niioaaonoaaiii oeiu “oeaeue”, “oeacaoaeue ia oeaeia”,

“iannea ec o?ao oeacaoaeae ia oeaeia”, “oeacaoaeue ia iannea

ec o?ao oeaeuo”, “ ooieoeey, aica?auathuay oeacaoaeue ia oeaeia”

e “oeacaoaeue ia ooieoeeth, aica?auathuoth oeaeia”.

16.8. TYPEDEF

Iienaiey, a eioi?uo “eeann iaiyoe”niaoeeoeoee?iaai eae

TYPEDEF, ia aucuaatho auaeaeaiey iaiyoe. aianoi yoiai iie ii-

?aaeaeytho eaeaioeoeeaoi?u ,eioi?ua iicaeiaa iiaeii eniieueciaaoue

oae, neiaii iie yaeythony eeth/aauie neiaaie, eiathueie iniia-

iua eee i?iecaiaeiua oeiu.

Ii?aaeaeythuaa-oei-eiy

eaeaioeoeeaoi?

A i?aaeaeao iaeanoe aeaenoaey iienaiey ni niaoeeoeeaoi?ii

TYPEDEF eaaeaeue eaeaioeoeeaoi?, yaeythueeny /anoueth ethaiai iie-

naoaey a yoii iienaiee, noaiiaeony neioaene/anee yeaeaaeaio-

iui eeth/aaiio neiao, eiathuaio oio oei , eioi?ue annioeee?oao

n eaeaioeoeeaoi?ii a iienaiiii a i. 16.4 Niunea. Iai?eia?,

iinea iienaiee

TYPEDEF INT MILES, >KLICKSP;

TYPEDEF STRUCT ( DOUBLE RE, IM; ) COMPLEX;

eiino?oeoeee

MILES DISTANCE;

EXTERN KLICKSP METRICP;

COMPLEX Z, *ZP;

· 210 –

noaiiayony caeiiiuie iienaieyie; i?e yoii oeiii DISTANCE ya-

eyaony INT, oeiii METRICP – “oeacaoaeue ia INT”, oeiii Z –

niaoeeoeoee?iaaiiay no?oeoo?a e oeiii ZP – oeacaoaeue ia oaeoth

no?oeoo?o.

Niaoeeoeeaoi? TYPEDEF ia aaiaeeo eaeeo-eeai niaa?oaiii ii-

auo oeiia, a oieueei ii?aaeaeyao neiiieiu aeey oeiia, eioi?ua

iiaeii auei au niaoeeoeoee?iaaoue e ae?oaei niiniaii. Oae a i?e-

aaaeaiiii auoa i?eia?a ia?aiaiiay DISTANCE n/eoaaony eiathuae

oi/ii oaeie aea oei, /oi e ethaie ae?oaie iauaeo, iienaiiue a

INT.

17. Iia?aoi?u

Ca eneeth/aieai iniai iaiaa?eaaaiuo neo/aaa, iia?aoi?u

auiieiythony iineaaeiaaoaeueii.

17.1. Iia?aoi?iia au?aaeaiea

Aieueoeinoai iia?aoi?ia yaeythony iia?aoi?iuie au?aaeaiey-

ie, eioi?ua eiatho oi?io

au?aaeaiea;

iau/ii iia?aoi?iua au?aaeaiey yaeythony i?enaaeaaieyie eee ia-

?auaieyie e ooieoeeyi.

17.2. Ninoaaiie iia?aoi? (eee aeie)

N oai /oiau aeiionoeoue aiciiaeiinoue eniieueciaaiey ianeieue-

eeo iia?aoi?ia oai, aaea iaeeaeaaony i?enoonoaea oieueei iaeiiai,

i?aaeoniao?eaaaony ninoaaiie iia?aoi? (eioi?ue oaeaea e yeae-

aaeaioii iacuaatho “aeieii”):

ninoaaiie iia?aoi?:

(nienie-iienaiee nienie-iia?aoi?ia

iaia iaia)

nienie-iienaiee:

iienaiea

iienaiea nienie-iienaiee

nienie-iia?aoi?ia:

iia?aoi?

iia?aoi? nienie-iia?aoi?ia

Anee eaeie-eeai eaeaioeoeeaoi? ec nienea-iienaiee aue iienai

?aiaa, oi ai a?aiy auiieiaiey aeiea aiaoiaa iienaiea iiaeaa-

eyaony e niiaa anooiaao a neeo iinea auoiaea ec aeiea.

Ethaay eieoeeaeecaoeey aaoiiaoe/aneeo e ?aaeno?aoeeiiiuo ia-

?aiaiiuo i?iaiaeeony i?e eaaeaeii aoiaea a aeie /a?ac aai ia/a-

ei. A ianoiyuaa a?aiy ?ac?aoaaony (ii yoi ieioay i?aeoeea)

ia?aaeaaaoue oi?aaeaiea aioo?ue aeiea; a oaeii neo/aa yoe eie-

oeeaeecaoeee ia auiieiythony. Eieoeeaeecaoeee noaoe/aneeo ia?a-

iaiiuo i?iaiaeyony oieueei iaeei ?ac, eiaaea ia/eiaaony auiieia-

iea i?ia?aiiu.

Iaoiaeyueany aioo?e aeiea aiaoiea iienaiey ia

?aca?ae?otho iaiyoe, oae /oi eo eieoeeaeecaoeey ia

?ac?aoaaony.

· 211 –

17.3. Oneiaiua iia?aoi?u Eiathony aeaa oi?iu oneiaiuo iia?aoi?ia:

IF (au?aaeaiea) iia?aoi?

IF (au?aaeaiea) iia?aoi? ELSE iia?aoi?

A iaieo neo/ayo au/aneyaony au?aaeaiea e, anee iii ioee/ii io

ioey, oi auiieiyaony ia?aue iiaeiia?aoi?. Ai aoi?ii neo/aa,

anee au?aaeaiea ?aaii ioeth, auiaeiyaony aoi?ie iiaeiia?aoi?.

Eae iau/ii, aeaoniuneaiiinoue “ELSE” ?ac?aoaaony naycuaaaieai

ELSE n iineaaeiei ano?a/athueiny IF, o eioi?iai iao ELSE.

17.4. Iia?aoi? WHILE

Iia?aoi? WHILE eiaao oi?io

WHILE (au?aaeaiea) iia?aoi?

Iiaeiia?aoi? auiieiyaony iiaoi?ii aei oao ii?, iiea cia/aiea

au?aaeaiey inoaaony ioee/iui io ioey. i?iaa?ea i?iecaiaeeony

ia?aae eaaeaeui auiieiaieai iia?aoi?a.

17.5. Iia?aoi? DO

Iia?aoi? DO eiaao oi?io

DO iia?aoi? WHILE (au?aaeaiey)

Iia?aoi? auiieiyaony iiaoi?ii aei oao ii?, iiea cia/aiea au?aaeaiey ia
noaiao ?aaiui ioeth. I?iaa?ea i?iecaiaeeony iinea eaaeaeiai auiieiaiey
iia?aoi?a.

17.6. Iia?aoi? FOR

Iia?aoi? FOR eiaao oi?io

(au?aaeaiea-1 ; au?aaeaiea-2 ; au?aaeaiea-3 )iia?aoi?

iaia iaia iaia

Iia?aoi? FOR yeaeaaeaioai neaaeothuaio

au?aaeaiea-1;

WHILE (au?aaeaiea-2) (

iia?aoi?

au?aaeaiea-3

)

Oaeei ia?acii, ia?aia au?aaeaiea ii?aaeaeyao eieoeeaeecaoeeth

oeeeea; aoi?ia niaoeeoeoe?oao i?iaa?eo, auiieiyaioth ia?aae eaae-

aeie eoa?aoeeae, oae /oi auoiae ec oeeeea i?ienoiaeeo oiaaea, eia-

aea cia/aiea au?aaeaiey noaiiaeony ioeai; o?aouea au?aaeaiea

/anoi caaeaao i?e?auaiea ia?aiao?a, eioi?ia i?iaiaeeony iinea

eaaeaeie eoa?aoeee.

Ethaia au?aaeaiea eee aeaaea ana iie iiaoo auoue iiouaiu. An-

ee ionoonoaoao aoi?ia au?aaeaiea, oi i?aaeeiaeaiea n WHILE n/e-

oaaony yeaeaaeaioiui WHILE(1); ae?oaea ionoonoaothuea au?aaea-

iey i?inoi iioneathony ec i?eaaaeaiiiai auoa ?anoe?aiey.

· 212 –

17.7. Iia?aoi? SWITCH

Iia?aoi? SWITCH (ia?aeeth/aoaeue), aucuaaao ia?aaea/o oi-

?aaeaiey e iaeiiio ec ianeieueeeo iia?aoi?ia, a caaeneiinoe io

cia/aiey au?aaeaiey. Iia?aoi? eiaao oi?io

SWITCH (au?aaeaiea) iia?aoi?

A au?aaeaiee i?iaiaeyony iau/iua a?eoiaoe/aneea i?aia?aciaa-

iey, ii ?acoeueoao aeieaeai eiaoue oei INT. Iia?aoi? iau/ii ya-

eyaony ninoaaiui. Ethaie iia?aoi? aioo?e yoiai iia?aoi?a ii-

aeao auoue iiia/ai iaeiei eee aieaa aa?eaioiui i?aoeenii CASE,

eiathuei oi?io:

CASE eiinoainoiia au?aaeaiea:

aaea eiinoaioiia au?aaeaiea aeieaeii eiaoue oei INT. Ieeaeea aeaa

aa?eaioiua eiinoaiou a iaeiii e oii aea ia?aeeth/aoaea ia iiaoo

eiaoue iaeeiaeiaia cia/aiea. oi/iia ii?aaeaeaiea eiinoaioiiai

au?aaeaiey i?eaiaeeony a i. 23.

E?iia oiai, iiaeao i?enoonoaiaaoue naiia aieueoaa iaeei iia-

?aoi?iue i?aoeen aeaea

DEFAULT:

I?e auiieiaiee iia?aoi?a SWITCH au/eneyaony aoiaeyuaa a

iaai au?aaeaiea e n?aaieaaaony n eaaeaeie aa?eaioiie eiinoai-

oie. Anee iaeia ec aa?eaioiuo eiinoaio ieacuaaaony ?aaiie

cia/aieth yoiai au?aaeaiey, oi oi?aaeaiea ia?aaeaaony iia?aoi-

?o, eioi?ue neaaeoao ca niaiaaeathuei aa?eaioiui i?aoeenii. An-

ee ie iaeia ec aa?eaioiuo eiinoaio ia niaiaaeaao ni cia/aieai

au?aaeaiey e anee i?e yoii i?enoonoaoao i?aoeen DEFAULT, oi

oi?aaeaiea ia?aaeaaony iia?aoi?o, iiia/aiiiio yoei i?aoeenii.

anee ie iaeei ec aa?eaioia ia iiaeoiaeeo e i?aoeen DEFAULT io-

noonoaoao, oi ie iaeei ec iia?aoi?ia a ia?aeeth/aoaea ia au-

iieiyaony.

Naie ii naaa i?aoeenu CASE e DEFAULT ia eciaiytho iioie

oi?aaeaiey, eioi?ia aani?aiyonaaiii i?ioiaeeo /a?ac oaeea

i?aoeenu. Aeey auoiaea ec ia?aeeth/aoaey niio?eoa iia?aoi?

BREAK, i. 17.8.

Iau/ii iia?aoi?, eioi?ue aoiaeeo a ia?aeeth/aoaeue, yaeyao-

ny ninoaaiui. Iienaiey iiaoo iiyaeyoueny a ia/aea yoiai iia-

?aoi?a, ii eieoeeaeecaoeee aaoiiaoe/aneeo e ?aaeno?iauo ia?a-

iaiiuo aoaeoo iayooaeoeaiuie.

17.8. Iia?aoi? BREAK

Iia?aoi?

BREAK;

aucuaaao caaa?oaiea auiieiaiey iaeiaiueoaai ioaaouaathuaai

yoio iia?aoi? iia?aoi?a WHILE, DO, FOR eee SWITCH; oi?aaea-

iea ia?aaeaaony iia?aoi?o, neaaeothuaio ca caaa?oaiiui iia?aoi-

?ii.

· 213 –

17.9. Iia?aoi? CONTINUE

Iia?aoi?

CONTINUE;

i?eaiaeeo e ia?aaea/a oi?aaeaiey ia i?iaeieaeathuoth oeeee /anoue

iaeiaiueoaai ioaaouaathuaai yoio iia?aoi? iia?aoi?a WHILE, DO

eee FOR; oi anoue ia eiiaoe oeeeea. Aieaa oi/ii, a eaaeaeii ec

iia?aoi?ia

WHILE(…) ( DO ( FOR(…) (

… … …

CONTIN: ; CONTIN: ; CONTIN: ;

) ) WHILE(…); )

Iia?aoi? CONTINUE yeaeaaeaioai iia?aoi?o GOTO CONTIN. (Ca

CONTIN: neaaeoao ionoie iia?aoi?; ni. I. 17.13.).

17.10. Iia?aoi? aica?aoa

Aica?auaiea ec ooieoeee a aucuaathuoth i?ia?aiio inouanoa-

eyaony n iiiiuueth iia?aoi?a RETURN, eioi?ue eiaao iaeio ec

neaaeothueo oi?i

RETURN;

RETURN au?aaeaiea;

A ia?aii neo/aa aica?auaaiia cia/aiea iaii?aaeaeaii. Ai aoi-

?ii neo/aa a aucuaathuoth ooieoeeth aica?auaaony cia/aiea au?a-

aeaiey. Anee o?aaoaony, au?aaeaiea i?aia?acoaony e oeio ooie-

oeee, a eioi?ie iii iiyaeyaony, eae a neo/aa i?enaaeaaiey.

Iiiaaeaiea ia eiiaoe ooieoeee yeaeaaeaioii aica?aoo aac aica?a-

uaaiiai cia/aiey.

17.11. Iia?aoi? GOTO

Oi?aaeaiea iiaeii ia?aaeaaaoue aaconeiaii n iiiiuueth iia?a-

oi?a

GOTO eaeaioeoeeaoi?1

eaeaioeoeeaoi? aeieaeai auoue iaoeie (i. 9.12), Eieaeeciaaiiie a

aeaiiie ooieoeee.

17.12. Iiia/aiiue iia?aoi?

Ia?aae ethaui iia?aoi?ii iiaeao noiyoue iiia/aiiue i?aoeen

aeaea

eaeaioeoeeaoi?:

eioi?ue neoaeeo aeey iienaiey eaeaioeoeeaoi?a a ea/anoaa iaoee.

Iaoee eniieuecothony oieueei aeey oeacaiey ianoa, eoaea ia?aaeaao-

ny oi?aaeaiea iia?aoi?ii GOTO. Iaeanoueth aeaenoaey iaoee yaey-

aony aeaiiay ooieoeey, ca eneeth/aieai ethauo iiaeaeieia, a eioi-

?uo oio aea eaeaioeoeeaoi? iienai niiaa. Niio?e i. 19.

· 214 –

17.13. Ionoie iia?aoi? Ionoie iia?aoi? eiaao oi?io:

;

Ionoie iia?aoi? ieacuaaaony iieaciui, oae eae ii iicaieyao

iinoaaeoue iaoeo ia?aae cae?uaathuae neiaeie ) ninoaaiiai iia-

?aoi?a eee oeacaoue ionoia oaei a iia?aoi?ao oeeeea, oaeeo eae

WHILE.

18. Aiaoiea ii?aaeaeaiey

C-i?ia?aiia i?aaenoaaeyao niaie iineaaeiaaoaeueiinoue aiao-

ieo ii?aaeaeaiee. Aiaoiaa ii?aaeaeaiea iienuaaao eaeaioeoeeaoi?

eae eiathuee eeann iaiyoe EXTERN (ii oiie/aieth), eee aiciiaeii

STATIC, e niaoeeoeoee?iaaiiue oei. Niaoeeoeeaoi? oeia (i. 16.2)

Oaeaea iiaeao auoue ionoui; a yoii neo/aa n/eoaaony, /oi oei

yaeyaony oeiii INT. Iaeanoue aeaenoaey aiaoieo ii?aaeaeaiee

?ani?ino?aiyaony aei eiioea oaeea, a eioi?ii iie i?eaaaeaiu,

oi/ii oae aea , eae aeeyiea iienaiee i?inoe?aaony aei eiioea

aeiea. Neioaenen aiaoieo ii?aaeaeaiee ia ioee/aaony io nei-

oaenena iienaiee, ca eneeth/aieai oiai, /oi oieueei ia yoii

o?iaia iiaeii i?eaiaeeoue oaeno ooieoeee.

18.1. Aiaoiaa ii?aaeaeaiea ooieoeee

Ii?aaeaeaiea ooieoeee eiaao oi?io

ii?aaeaeaiea-ooieoeee:

niaoeeoeeaoi?u-iienaiey iienaoaeue-ooieoeee

oaei-ooieoeee

iaia

Aaeeinoaaiiuie niaoeeoeeaoi?aie eeanna iaiyoe, aeiioneaaiuie a

ea/anoaa niaoeeoeeaoi?ia-iienaiey, yaeythony EXTERN eee

STATIC; i ?acee/ee iaaeaeo ieie niio?e i. 19.2. Iienaoaeue ooi-

eoeee iiaeiaai iienaoaeth aeey “ooieoeee, aica?auathuae…”, ca

eneeth/aieai oiai, /oi ii ia?a/eneyao oi?iaeueiua ia?aiao?u

ii?aaeaeyaiie ooieoeee.

Ienaoaeue-ooieoeee:

iienaoaeue (nienie-ia?aiao?ia

iaia)

nienie ia?aiao?ia:

eaeaioeoeeaoi?

eaeaioeoeeaoi?, nienie-ia?aiao?ia

oaei-ooieoeee eiaao oi?io

oaei-ooieoeee:

nienie-iienaiee ninoaaiie-iia?aoi?

· 215 –

Eaeaioeoeeaoi?u ec nienea ia?aiao?ia e oieueei iie iiaoo

auoue iienaiu a nienea iienaiee. Ethaie eaeaioeoeeaoi?, oei ei-

oi?iai ia oeacai, n/eoaaony eiathuei oei INT. Aaeeinoaaiiui

aeiionoeiui caeanue niaoeeoeeaoi?ii eeanna iaiyoe yaeyaony

REGISTER; anee oaeie eeann iaiyoe niaoeeoeoee?iaai, oi a ia/a-

ea auiieiaiey ooieoeee niioaaonoaothuee oaeoe/aneee ia?aiao?

eiie?oaony, anee yoi aiciiaeii, a ?aaeno?.

Aio i?inoie i?eia? iieiiai ii?aaeaeaiey ooieoeee:

INT MAX(A, B, C)

INT A, B, C;

(

INT M;

M = (A>B) ? A:B;

RETURN((M>C) ? M:C);

)

Caeanue INT – niaoeeoeeaoi?-oeia, MAX(A,B,C) – iienaoaeue-ooie-

oeee, INT A,B,C; – nienie-iienaiee oi?iaeueiuo ia?aiao?ia, (

… ) – Aeie, niaea?aeauee oaeno iia?aoi?a.

A ycuea “C” ana oaeoe/aneea ia?aiao?u oeia FLOAT i?aia-

?acothony e oeio DOUBLE, oae /oi iienaiey oi?iaeueiuo ia?aiao-

?ia, iauyaeaiiuo eae FLOAT, i?eniiniaeaiu i?i/anoue ia?aiao?u

oeia DOUBLE. Aiaeiae/ii, iineieueeo nnueea ia iannea a ethaii

eiioaenoa (a /anoiinoe a oaeoe/aneii ia?aiao?a) ?anniao?eaa-

aony eae oeacaoaeue ia ia?aue yeaiaio ianneaa, iienaiey oi?-

iaeueiuo ia?aiao?ia aeea “iannea …” i?eniiniaeaiu i?i/anoue

: “oeacaoaeue ia …”. E iaeiiaoe, iineieueeo no?oeoo?u,

iauaaeeiaiey e ooieoeee ia iiaoo auoue ia?aaeaiu ooieoeee, aann-

iuneaiii iienuaaoue oi?iaeueiue ia?aiao? eae no?oeoo?o,

iauaaeeiaiea eee ooieoeeth (oeacaoaee ia oaeea iauaeou, eiia/-

ii, aeiioneathony).

18.2. Aiaoiea ii?aaeaeaiey aeaiiuo

Aiaoiaa ii?aaeaeaiea aeaiiuo eiaao oi?io

ii?aaeaeaiea-aeaiiuo:

iienaiea

Eeannii iaiyoe oaeeo aeaiiuo iiaeao auoue EXTERN (a /anoiinoe,

ii oiie/aieth) eee STATIC, ii ia AUTO eee REGISTER.

19. I?aaeea, ii?aaeaeythuea iaeanoue aeaenoaey

Any C-i?ia?aiia iaiaycaoaeueii eiiieee?oaony iaeiia?aiai-

ii; enoiaeiue oaeno i?ia?aiiu iiaeao o?aieoueny a ianeieueeeo

oaeeao e ?aiaa neiiieee?iaaiiua i?ioeaaeo?u iiaoo caa?oaeaoueny

ec aeaeeioae. Naycue iaaeaeo ooieoeeyie iiaeao inouanoaeyoueny eae

/a?ac yaiua ia?auaiey, oae e a ?acoeueoaoa iaieioee?iaaiey n

aiaoieie aeaiiuie.

Iiyoiio neaaeoao ?anniio?aoue aeaa aeaea iaeanoae aeaenoaey:

ai-ia?auo, oo, eioi?ay iiaeao auoue iacaaia eaene/aneie ia-

eanoueth aeaenoaey eaeaioeoeeaoi?a e eioi?ay ii nouanoao yaeyao-

ny oie iaeanoueth a i?ia?aiia, aaea yoio eaeaioeoeeaoi? iiaeii

eniieueciaaoue, ia aucuaay aeeaaiinoe/aneiai niiauaiey “iaii?a-

aeaeaiiue eaeaioeoeeaoi?”; e ai-aoi?uo, iaeanoue aeaenoaey, ei-

oi?ay naycaia n aiaoieie eaeaioeoeeaoi?aie e eioi?ay oa?aeoa-

?ecoaony i?aaeeii, /oi nnueee ia iaeei e oio aea aiaoiee eaeai-

oeoeeaoi? yaeythony nnueeaie ia iaeei e oio aea iauaeo.

· 216 –

19.1. Eaene/aneay iaeanoue aeaenoaey

Eaene/aneay iaeanoue aeaenoaey eaeaioeoeeaoi?ia, iienaiiuo

ai aiaoieo ii?aaeaeaieyo, i?inoe?aaony io ii?aaeaeaiey aei eii-

oea enoiaeiiai oaeea, a eioi?ii ii iaoiaeeony. Eaene/aneay ia-

eanoue aeaenoaey eaeaioeoeeaoi?ia, yaeythueony oi?iaeueiuie ia?a-

iao?aie, ?ani?ino?aiyaony ia oo ooieoeeth, e eioi?ie iie ioii-

nyony. Eaene/aneay iaeanoue aeaenoaey eaeaioeoeeaoi?ia, iienai-

iuo a ia/aea aeiea, i?inoe?aaony aei eiioea yoiai aeiea. Eae-

ne/aneie iaeanoueth aeaenoaey iaoie yaeyaony oa ooieoeey, a ei-

oi?ie iie iaoiaeyony.

Iineieueeo ana ia?auaiey ia iaeei e oio aea aiaoiee eaeaioe-

oeeaoi? ia?auathony e iaeiiio e oiio aea iauaeoo (ni. I. 19.2),

Eiiieeyoi? i?iaa?yao ana iienaiey iaeiiai e oiai aea aiaoiaai

eaeaioeoeeaoi?a ia niaianoeiinoue; a aeaenoaeoaeueiinoe eo ia-

eanoue aeaenoaey ?ani?ino?aiyaony ia aanue oaee, a eioi?ii iie

iaoiaeyony.

Ai anao neo/ayo, iaeiaei, anoue iaeioi?ue eaeaioeoeeaoi?,

yaiui ia?acii iienai a ia/aea aeiea, aeeth/ay e aeie, eioi?ue

ia?acoao ooieoeeth, oi aeaenoaea ethaiai iienaiey yoiai eaeaioe-

oeeaoi?a aia aeiea i?einoaiaaeeaaaony aei eiioea yoiai aeiea.

Iaiiiiei oaeaea (i. 16.5), *oi eaeaioeoeeaoi?u, niioaaono-

aothuea iau/iui ia?aiaiiui, n iaeiie noi?iiu, e eaeaioeoeeaoi-

?u, niioaaonoaothuea /eaiai e y?eueai no?oeoo? e iauaaeeiaiee,

n ae?oaie noi?iiu, oi?ie?otho aeaa iaia?anaeathueony eeanna, ei-

oi?ua ia anooiatho a i?ioeai?a/ea. *eaiu e y?euee iiae/eiythony

oai aea naiui i?aaeeai ii?aaeaeaiey iaeanoae aeaenoaey, eae e

ae?oaea eaeaioeoeeaoi?u. Eiaia, niaoeeoeoee?oaiua n iiiiuueth

TYPEDEF, aoiaeyo a oio aea eeann, /oi e iau/iua eaeaioeoeeaoi-

?u. Iie iiaoo auoue ia?aii?aaeaeaiu ai aioo?aiieo aeieao, ii

ai aioo?aiiai iienaiee oei aeieaeai auoue oeacai yaii:

TYPEDEF FLOAT DISTANCE;

(

AUTO INT DISTANCE;

Ai aoi?ii iienaiee niaoeeoeeaoi? oeia INT aeieaeai i?enoonoai-

aaoue, oae eae a i?ioeaiii neo/aa yoi iienaiea aoaeao i?eiyoi

ca iienaiea aac iienaoaeae n oeiii DISTANCE (i?ei. Aaoi?a:

niaeaneoanue, /oi eaae caeanue oiiie.).

19.2. Iaeanoue aeaenoaey aiaoieo eaeaioeoeeaoi?ia

Anee ooieoeey nnueaaony ia eaeaioeoeeaoi?, iienaiiue eae

EXTERN, oi aaea-oi n?aaee oaeeia eee aeaeeioae, ia?acothueo

iieioth i?ia?aiio, aeieaeii niaea?aeaoueny aiaoiaa ii?aaeaeaiea

yoiai eaeaioeoeeaoi?a. Ana ooieoeee aeaiiie i?ia?aiiu, eioi?ua

nnueathony ia iaeei e oio aea aiaoiee eaeaioeoeeaoi?, nnueathony

ia iaeei e oio aea iauaeo, oae /oi neaaeoao iicaaioeoueny, /oiau

niaoeeoeoee?iaaiiua a yoii ii?aaeaeaiee oei e ?acia? auee nia-

ianoeiu n oeiii e ?acia?ii, oeacuaaaiuie a eaaeaeie ooieoeee,

eioi?ay nnueaaony ia yoe aeaiiua.

· 217 –

Iiyaeaiea eeth/aaiai neiaa EBTERN ai aiaoiai ii?aaeaeaiee

oeacuaaao ia oi, /oi iaiyoue aeey iienaiiuo a iai eaeaioeoeea-

oi?ia aoaeao auaeaeaia a ae?oaii oaeea. Neaaeiaaoaeueii, a ninoi-

yuae ec iiiaeo oaeeia i?ia?aiia aiaoiaa ii?aaeaeaiea eaeaioe-

oeeaoi?a, ia niaea?aeauaa niaoeeoeeaoi?a EXTERN, aeieaeii iiya-

eyoueny ?iaii a iaeiii ec yoeo oaeeia. ethaua ae?oaea oaeeu, ei-

oi?ua aeaeatho aeaoue aiaoiaa ii?aaeaeaiea yoiai eaeaioeoeeaoi?a,

aeieaeiu aeeth/aoue a yoi ii?aaeaeaiea neiai EXTERN. Eaeaioeoeea-

oi? iiaeao auoue eieoeeaeece?iaai oieueei a oii iienaiee, eioi-

?ia i?eaiaeeo e auaeaeaieth iaiyoe.

Eaeaioeoeeaoi?u, aiaoiaa ii?aaeaeaiea eioi?uo ia/eiaaony

ni neiaa STATIC, iaaeinooiiu ec ae?oaeo oaeeia. Ooieoeee iiaoo

auoue iienaiu eae STATIC.

20. No?iee oi?aaeaiey eiiieeyoi?ii

Eiiieeyoi? ycuea “C” niaea?aeeo i?ai?ioeanni?, eioi?ue iic-

aieyao inouanoaeyoue iae?iiiaenoaiiaee, oneiaioth eiiieeyoeeth e

aeeth/aiea eiaiiaaiiuo oaeeia. No?iee, ia/eiathueany n #, ia-

uathony n yoei i?ai?ioeanni?ii. Neioaenen yoeo no?ie ia naycai

n inoaeueiui ycueii; iie iiaoo iiyaeyoueny a ethaii ianoa e eo

aeeyiea ?ani?ino?aiyaony (iacaaeneii io iaeanoe aeaenoaey) aei

eiioea enoiaeiiai i?ia?aiiiiai oaeea.

20.1. Caiaia eaenai

Oi?aaeythuay eiiieeyoi?ii no?iea aeaea

#DEFINE eaeaioeoeeaoi? no?iea-eaenai

(Ia?aoeoa aieiaiea ia ionoonoaea a eiioea oi/ee n caiy-

oie) i?eaiaeeo e oiio, /oi i?ai?ioeanni? caiaiyao iineaaeothuea

aoiaeaeaiey yoiai eaeaioeoeeaoi?a ia oeacaiioth no?ieo eaenai.

No?iea aeaea

#DEFINE eaeaioeoeeaoi?

(eaeaioeoeeaoi?,…,eaeaioeoeeaoi?)no?iea eaenai

aaea iaaeaeo ia?aui eaeaioeoeeaoi?ii e ioe?uaathuaeny neiaeie (

iao i?iaaea, i?aaenoaaeyao niaie iae?iii?aaeaeaiea n a?aoiai-

oaie. Iineaaeothuaa aoiaeaeaiea ia?aiai eaeaioeoeeaoi?a, ca eioi-

?ui neaaeoao ioe?uaathuay neiaea ‘(‘, iineaaeiaaoaeueiinoue ?ac-

aeaeaiiuo caiyouie eaenai e cae?uaathuay neiaea ‘)’, caiaiytho-

ny no?ieie eaenai ec ii?aaeaeaiey. eaaeaeia aoiaeaeaiea eaeaioeoe-

eaoi?a, oiiiyiooiai a nienea oi?iaeueiuo ia?aiao?ia a ii?aaea-

eaiee , caiaiyaony niioaaonoaothuae no?ieie eaenai ec ia?aua-

iey. Oaeoe/aneeie a?aoiaioaie a ia?auaiee yaeythony no?iee

eaenai, ?acaeaeaiiua caiyouie; iaeiaei caiyoua, aoiaeyuea a ca-

eaau/aiiua no?iee eee caeeth/aiiua a e?oaeua neiaee, ia ?ac-

aeaeytho a?aoiaioia. Eiee/anoai oi?iaeueiuo e oaeoe/aneeo ia?a-

iao?ia aeieaeii niaiaaeaoue. Oaeno aioo?e no?iee eee neiaieueiie

eiinoaiou ia iiaeeaaeeo caiaia.

A iaieo neo/ayo caiaiaiiay no?iea i?iniao?eaaaony niiaa

n oeaeueth iaia?oaeaiey ae?oaeo ii?aaeaeaiiuo eaeaioeoeeaoi?ia. A

iaieo neo/ayo neeoeii aeeeiiay no?iea ii?aaeaeaiey iiaeao auoue

i?iaeieaeaia ia ae?oaie no?iea, anee iiianoeoue a eiioea i?iaeie-

aeaaiie no?iee ia?aoioth einoth /a?oo .

· 218 –

Iienuaaaiay aiciiaeiinoue iniaaiii iieacia aeey ii?aaeaeaiey

“iauyaeyaiuo eiinoaio”, eae, iai?eia?,

#DEFINE TABSIZE 100

INT TABLE[TABSIZE];

Oi?aaeythuay no?iea aeaea

#UNDEF eaeaioeoeeaoi?

i?eaiaeeo e ioiaia i?ai?ioeanni?iiai ii?aaeaeaiey aeaiiiai eaeai-

oeoeeaoi?a.

20.2. Aeeth/aiea oaeeia

No?iea oi?aaeaiey eiiieeyoi?ii aeaea

#INCLUDE “FILENAME”

i?eaiaeeo e caiaia yoie no?iee ia ana niaea?aeeiia oaeea n eia-

iai FILENAME. Oaee n yoei eiaiai nia/aea euaony a ni?aai/ie-

ea ia/aeueiiai enoiaeiiai oaeea, a caoai a iineaaeiaaoaeueiinoe

noaiaea?oiuo iano. A ioee/ea io yoiai oi?aaeythuay no?iea aeaea

#INCLUDE

euao oaee oieueei a noaiaea?oiuo ianoao e ia i?iniao?eaaao

ni?aai/iee enoiaeiiai oaeea.

No?iee #INCLUDE iiaoo auoue aeiaeaiiuie.

20.3. Oneiaiay eiiieeyoeey

No?iea oi?aaeaiey eiiieeyoi?ii aeaea

#IF eiinoaioiia au?aaeaiea

i?iaa?yao, ioee/ii ee io ioey cia/aiea eiinoaioiiai au?aaea-

iey (ni. I. 15). Oi?aaeythuay no?iea aeaea

#IF DEF eaeaioeoeeaoi?

i?iaa?yao, ii?aaeaeai ee yoio eaeaioeoeeaoi? a ianoiyuee ii-

iaio a i?ai?ioeanni?a, o.a. Ii?aaeaeai ee yoio eaeaioeoeeaoi? n

iiiiuueth oi?aaeythuae no?iee #DEFINE.

21. Iayaiua iienaiey

Ia anaaaea yaeyaony iaiaoiaeeiui niaoeeoeoee?iaaoue e eeann

iaiyoe e oei eaeaioeoeeaoi?a a iienaiee. Ai aiaoieo ii?aaeaea-

ieyo e iienaieyo oi?iaeueiuo ia?aiao?ia e /eaiia no?oeoo?

eeann iaiyoe ii?aaeaeyaony ii eiioaenoo. Anee a iaoiaeyuainy

aioo?e ooieoeee iienaiee ia oeacai oei, a oieueei eeann iaiy-

oe, oi i?aaeiieaaaaony, /oi eaeaioeoeeaoi? eiaao oei INT; anee

ia oeacai eeann iaiyoe, a oieueei oei, oi eaeaioeoeeaoi? i?aae-

iieaaaaony iienaiiui eae AUTO. Eneeth/aiea ec iineaaeiaai i?a-

aeea aeaaony aeey ooieoeee, iioiio /oi niaoeeoeeaoi? AUTO aeey

ooieoeee yaeyaony aanniuneaiiui (ycue “C” ia a ninoiyiee eii-

ieee?iaaoue i?ia?aiio a noae); anee eaeaioeoeeaoi? eiaao oei

“ooieoeey, aica?auathuay …”, oi ii i?aaeiieaaaaony iayaii

iienaiiui eae EXTERN.

· 219 –

Aoiaeyuee a au?aaeaiea e iaiienaiiue ?aiaa eaeaioeoeeaoi?,

ca eioi?ui neaaeoao neiaea ( , n/eoaaony iienaiiui ii eiioae-

noo eae “ooieoeey, aica?auathuay INT”.

22. Niiaa i oeiao

A yoii ?acaeaea iaiauathony naaaeaiey ia iia?aoeeyo, eioi?ua

iiaeii i?eiaiyoue oieueei e iauaeoai ii?aaeaeaiiuo oeiia.

22.1. No?oeoo?u e iauaaeeiaiey

Oieueei aeaa aaue iiaeii naeaeaoue ni no?oeoo?ie eee iauaaee-

iaieai: iacaaoue iaeei ec eo /eaiia (n iiiiuueth iia?aoeee) eee

ecaea/ue eo aae?an ( n iiiiuueth oia?iie iia?aoeee &). Ae?oaea

iia?aoeee, oaeea eae i?enaaeaaiea ei eee ec ieo e ia?aaea/a eo

a ea/anoaa ia?aiao?ia, i?eaiaeyo e niiauaieth ia ioeaea. A ao-

aeouai iaeeaeaaony, /oi yoe iia?aoeee, ii ia iaycaoaeueii ea-

eea-eeai ae?oaea, aoaeoo ?ac?aoaiu.

A i. 15.1 Aiai?eony, /oi i?e i?yiie eee einaaiiie nnueea

ia no?oeoo?o (n iiiiuueth . Eee ->) eiy ni?aaa aeieaeii auoue

/eaiii no?oeoo?u, iacaaiiie eee oeacaiiie au?aaeaieai neaaa.

Yoi ia?aie/aiea ia iaaycuaaaony no?iai eiiieeyoi?ii, /oiau

aeaoue aiciiaeiinoue iaieoe i?aaeea oeiia. A aeaenoaeoaeueiinoe

ia?aae ‘.’ aeiioneaaony ethaia L-cia/aiea e caoai i?aaeiieaaaao-

ny, /oi yoi L-cia/aiea eiaao oi?io no?oeoo?u, aeey eioi?ie

noiyuaa ni?aaa eiy yaeyaony /eaiii. Oaeei aea ia?acii, io au-

?aaeaiey, noiyuaai ia?aae ‘->’, o?aaoaony oieueei auoue oeacaoa-

eai eee oeaeui. A neo/aa oeacaoaey i?aaeiieaaaaony, /oi ii

oeacuaaao ia no?oeoo?o, aeey eioi?ie noiyuaa ni?aaa eiy yaey-

aony /eaiii. A neo/aa oeaeiai iii ?anniao?eaaaony eae aani-

ethoiue aae?an niioaaonoaothuae no?oeoo?u, caaeaiiue a aaeeieoeao

iaoeiiie iaiyoe.

Oaeea no?oeoo?u ia yaeythony ia?aiineiuie.

22.2. Ooieoeee

Oieueei aeaa aaue iiaeii naeaeaoue n ooieoeeae: aucaaoue aa eee

ecaea/ue aa aae?an. Anee eiy ooieoeee aoiaeeo a au?aaeaiea ia a

iiceoeee eiaie ooieoeee, niioaaonoaothuae ia?auaieth e iae, oi

aaia?e?oaony oeacaoaeue ia yoo ooieoeeth. Neaaeiaaoaeueii, /oiau

ia?aaeaoue iaeio ooieoeeth ae?oaie, iiaeii iaienaoue

INT F();

G(F);

Oiaaea ii?aaeaeaiea ooieoeee G iiaei au auaeyaeaoue oae:

G(FUNCP)

INT(*FUNCP)();

(

(*FUNCP)();

)

Ia?aoeoa aieiaiea, /oi a aucuaathuae i?ioeaaeo?a ooieoeey F aeie-

aeia auoue iienaia yaii, iioiio /oi ca aa iiyaeaieai a G(F) ia

neaaeoao neiaea ( .

· 220 –

22.3. Ianneau, oeacaoaee e eiaeaenaoeey

Eaaeaeue ?ac, eiaaea eaeaioeoeeaoi?, eiathuee oei ianneaa,

iiyaeyaony a au?aaeaiee, ii i?aia?acoaony a oeacaoaeue ia ia?-

aue /eai yoiai ianneaa. Ec-ca yoiai i?aia?aciaaiey ianneau

ia yaeythony L-cia/aieyie. Ii ii?aaeaeaieth iia?aoeey eiaeaenaoeey

[] eioa?i?aoe?oaony oaeei ia?acii, /oi E1[E2] n/eoaaony

eaeaioe/iui au?aaeaieth *((a1)+(a2)). Niaeanii i?aaeeai i?aia-

?aciaaiee, i?eiaiyaiui i?e iia?aoeee +, anee E1 – iannea, a

a2 – oeaeia, oi a1[a2] nnueaaony ia a2-e /eai ianneaa a1. Ii-

yoiio ianiio?y ia ianeiiao?e/iue aeae iia?aoeey eiaeaenaoeee ya-

eyaony eiiiooaoeaiie.

A neo/aa iiiaiia?iuo ianneaia i?eiaiyaony iineaaeiaaoaeue-

iia i?aaeei. Anee a yaeyaony N-ia?iui ianneaii ?acia?a

I*J*…*K, oi i?e iiyaeaiee a au?aaeaiee a i?aia?acoaony a

oeacaoaeue ia (N-1)-ia?iue iannea ?acia?a J*…*K. Anee iia-

?aoeey * eeai yaii, eeai iayaii, eae ?acoeueoao eiaeaenaoeee,

i?eiaiyaony e yoiio oeacaoaeth, oi ?acoeueoaoii iia?aoeee aoaeao

oeacaiiue (N-1)-ia?iue iannea, eioi?ue nai iaiaaeeaiii i?aia-

?acoaony a oeacaoaeue.

?anniio?ei, iai?eia?, iienaiea

INT X[3][5];

Caeanue X iannea oeaeuo ?acia?a 3*5. I?e iiyaeaiee a au?aaeaiee

X i?aia?acoaony a oeacaoaeue ia ia?aue ec o?ao ianneaia ec 5

oeaeuo. A au?aaeaiee X[I], eioi?ia yeaeaaeaioii *(X+I), nia/a-

ea X i?aia?acoaony a oeacaoaeue oae, eae iienaii auoa; caoai

I i?aia?acoaony e oeio X, /oi aucuaaao oiiiaeaiea I ia aeeeio

iauaeoa, ia eioi?ue oeacuaaao oeacaoaeue, a eiaiii ia 5 oeaeuo

iauaeoia. ?acoeueoaou neeaaeuaathony, e i?eiaiaiea einaaiiie

aae?anaoeee aeaao iannea (ec 5 oeaeuo), eioi?ue a naith i/a?aaeue

i?aia?acoaony a oeacaoaeue ia ia?aia ec yoeo oeaeuo. Anee a

au?aaeaiea aoiaeeo e ae?oaie eiaeaen, oi oaaea naiay a?aoiaioaoeey

i?eiaiyaony niiaa; ?acoeueoaoii ia yoio ?ac aoaeao oeaeia.

Ec anaai yoiai neaaeoao, /oi ianneau a ycuea “C” o?aiyony

iino?i/ii ( iineaaeiee eiaeaen eciaiyaony auno?aa anaai) e /oi

ia?aue eiaeaen a iienaiee iiiiaaao ii?aaeaeeoue iauaa eiee/ano-

ai iaiyoe, o?aaoaiia aeey o?aiaiey ianneaa, ii ia ea?aao ie-

eaeie ae?oaie ?iee a au/eneaieyo, naycaiiuo n eiaeaenaoeeae.

22.4. ssaiua i?aia?aciaaiey oeacaoaeae

?ac?aoathony ii?aaeaeaiiua i?aia?aciaaiey, n eniieueciaaie-

ai oeacaoaeae , ii iie eiatho iaeioi?ua caaenyuea io eiie?ao-

iie ?aaeecaoeee aniaeou. Ana yoe i?aia?aciaaiey caaeathony n

iiiiuueth iia?aoeee yaiiai i?aia?aciaaiey oeia; ni. I. 15.2 e

16.7.

Oeacaoaeue iiaeao auoue i?aia?aciaai a ethaie ec oeaei/eneai-

iuo oeiia, aeinoaoi/ii aieueoie aeey aai o?aiaiey. O?aaoaony ee

i?e yoii INT eee LONG, caaeneo io eiie?aoiie iaoeiu. I?aia-

?acothuay ooieoeey oaeaea yaeyaony iaoeiii-caaeneiie, ii iia

aoaeao aiieia anoanoaaiiie aeey oao, eoi ciaao no?oeoo?o aae?a-

naoeee a iaoeia. Aeaoaee aeey iaeioi?uo eiie?aoiuo iaoei i?eai-

aeyony ieaea.

Iauaeo oeaei/eneaiiiai oeia iiaeao auoue yaiui ia?acii i?a-

ia?aciaai a oeacaoaeue. oaeia i?aia?aciaaiea anaaaea ia?aaiaeeo

i?aia?aciaaiiia ec oeacaoaey oeaeia a oio aea naiue oeacaoaeue,

ii a ae?oaeo neo/ayo iii aoaeao iaoeiii-caaeneiui.

· 221 –

Oeacaoaeue ia iaeei oei iiaeao auoue i?aia?aciaai a oeaca-

oaeue ia ae?oaie oei. Anee i?aia?acoaiue oeacaoaeue ia oeacuaa-

ao ia iauaeou, eioi?ua iiaeoiaeyuei ia?acii au?aaiaiu a iaiy-

oe, oi ?acoeueoe?othuee oeacaoaeue iiaeao i?e eniieueciaaiee au-

cuaaoue ioeaee aae?anaoeee. Aa?aioe?oaony, /oi oeacaoaeue ia

iauaeo caaeaiiiai ?acia?a iiaeao auoue i?aia?aciaai a oeacaoaeue

ia iauaeo iaiueoaai ?acia?a e niiaa ia?aoii, ia i?aoa?iaa i?e

yoii eciaiaiey.

Iai?eia?, i?ioeaaeo?a ?ani?aaeaeaiey iaiyoe iiaea au i?eie-

iaoue cai?in ia ?acia? auaeaeyaiiai iauaeoa a aaeoao, a aica-

?auaoue oeacaoaeue ia neiaieu; yoi iiaeii auei au eniieueciaaoue

neaaeothuei ia?acii.

EXTERN CHAR *ALLOC();

DOUBLE *DP;

DP=(DOUBLE*) ALLOC(SIZEOF(DOUBLE));

*DP=22.0/7.0;

Ooieoeey ALLOC aeieaeia iaania/eaaoue (iaoeiii-caaeneiui niini-

aii), /oi aica?auaaiia ath cia/aiea aoaeao iiaeoiaeyuei aeey i?a-

ia?aciaaiey a oeacaoaeue ia DOUBLE; a oaeii neo/aa eniieueci-

aaiea yoie ooieoeee aoaeao ia?aiineiui.

I?aaenoaaeaiea oeacaoaey ia PDP-11 niioaaonoaoao 16-aeoi-

aiio oeaeiio e ecia?yaony a aaeoao. Iauaeou oeia CHAR ia eia-

tho ieeaeeo ia?aie/aiee ia au?aaieaaiea; ana inoaeueiua iauae-

ou aeieaeiu eiaoue /aoiua aae?ana.

Ia HONEYWELL 6000 oeacaoaeue niioaaonoaoao 36-aeoiaiio

oeaeiio; neiao niioaaonoaoao 18 eaauo aeoia e aeaa iaiin?aaeno-

aaiii i?eiueathueo e iei ni?aaa aeoa, eioi?ua auaeaeytho neiaie

a neiaa. Oaeei ia?acii, oeacaoaee ia neiaieu ecia?ythony a

aaeeieoeao 2 a noaiaie 16 aaeoia; ana inoaeueiia ecia?yaony a

aaeeieoeao 2 a noaiaie 18 iaoeiiuo neia. Aaee/eiu oeia DOUBLE

e niaea?aeauea eo aa?aaaou aeieaeiu au?aaieaaoueny ii /aoiui aae-

?anai neia (0 ii iiaeoeth 2 a noaiaie 19). Yai IBM 370 e

INTERDATA 8/32 noiaeiu iaaeaeo niaie. Ia iaaeo iaoeiao aae?ana

ecia?ythony a aaeoao; yeaiaioa?iua iauaeou aeieaeiu auoue au?ia-

iaiu ii a?aieoea, ?aaiie eo aeeeia, oae /oi oeacaoaee ia SHORT

aeieaeiu auoue e?aoiu aeaoi, ia INT e FLOAT – /aou?ai e ia

DOUBLE – ainueie. Aa?aaaou au?aaieaathony ii naiie no?iaie

a?aieoea, o?aaoaiie eaeei-eeai ec eo yeaiaioia.

23. Eiinoaioiua au?aaeaiey

A ianeieueeeo ianoao a ycuea “C” o?aaothony au?aaeaiey, ei-

oi?ua iinea au/eneaiey noaiiayony eiinoaioaie: iinea aa?eai-

oiiai i?aoeena CASE, a ea/anoaa a?aieoe ianneaia e a eieoeea-

eecaoi?ao. A ia?auo aeaoo neo/ayo au?aaeaiea iiaeao niaea?aeaoue

oieueei oeaeua eiinoaiou, neiaieueiua eiinoaiou e au?aaeaiey

SIZEOF, aiciiaeii naycaiiua eeai aeia?iuie iia?aoeeyie

+ – * / . % & ! * > == 1= =

eeai oia?iuie iia?aoeeyie

– ^

eeai oa?ia?iie iia?aoeeae ?:

· 222 –

E?oaeua neiaee iiaoo eniieueciaaoueny aeey a?oiie?iaee, ii ia

aeey ia?auaiey e ooieoeeyi.

A neo/aa eieoeeaeecaoi?ia aeiioneaaony aieueoay (oaea?aiea

ia aoeao i) naiaiaea; e?iia ia?a/eneaiiuo auoa eiinoaioiuo

au?aaeaiee iiaeii oaeaea i?eiaiyoue oia?ioth iia?aoeeth & e aiaoiei

eee noaoe/aneei iauaeoai e e aiaoiei eee noaoe/aneei ianne-

aai, eiathuei a ea/anoaa eiaeaenia eiinoaioiia au?aaeaiea.

Oia?iay iia?aoeey & iiaeao auoue oaeaea i?eiaiaia iayaii, a ?a-

coeueoaoa iiyaeaiey iaeiaeaene?iaaiiuo ianneaia e ooieoeee. In-

iiaiia i?aaeei caeeth/aaony a oii, /oi iinea au/eneaiey eie-

oeeaeecaoi? aeieaeai noaiiaeony eeai eiinoaioie, eeai aae?anii

?aiaa iienaiiiai aiaoiaai eee noaoe/aneiai iauaeoa iethn eee

ieion eiinoaioa.

24. Niia?aaeaiey i ia?aiineiinoe

Iaeioi?ua /anoe ycuea “C” ii naiae nooe iaoeiii-caaene-

iu. Neaaeothuea ieaea ia?a/eneaiea iioaioeeaeueiuo o?oaeiinoae oi-

oy e ia yaeythony anaiauaiethueie, ii auaeaeyao iniiaiua ec

ieo.

Eae iieacaea i?aeoeea, aii?inu, oeaeeeii naycaiiua n ai-

ia?aoiui iai?oaeiaaieai, oaeea eae ?acia? neiaa, naienoaa

ieaaathuae a?eoiaoeee e oeaeiai aeaeaiey, ia i?aaenoaaeytho ini-

aaiiuo cao?oaeiaiee. Ae?oaea aniaeou aiia?aoiuo n?aaenoa iaoi-

aeyo naia io?aaeaiea a ?acee/iuo ?aaeecaoeeyo. Iaeioi?ua ec

ieo, a /anoiinoe, ciaeiaia ?anoe?aiea (i?aia?acothuaa io?eoea-

oaeueiue neiaie a io?eoeaoaeueiia oeaeia) e ii?yaeie, a eioi?ii

iiiauathony aaeou a neiaa, i?aaenoaaeytho niaie iai?eyoiinoue,

eioi?ay aeieaeia ouaoaeueii ioneaaeeaaoueny. Aieueoeinoai ec in-

oaeueiuo i?iaeai yoiai oeia ia aucuaaao neieueei-ieaoaeue cia/e-

oaeueiuo cao?oaeiaiee.

*enei ia?aiaiiuo oeia REGISTER, eioi?ia oaeoe/anee iiaeao

auoue iiiauaii a ?aaeno?u, iaiyaony io iaoeiu e iaoeia, oaeaea

eae e iaai? aeiionoeiuo aeey ieo oeiia. Oai ia iaiaa ana eii-

ieeyoi?u ia naieo iaoeiao ?aaioatho iaaeeaaeauei ia?acii; eeo-

iea eee iaaeiionoeiua ?aaeno?iaua iienaiey eaii?e?othony.

Iaeioi?ua o?oaeiinoe aicieeatho oieueei i?e eniieueciaaiee

niiieoaeueiie i?aeoeee i?ia?aiie?iaaiey. Ienaoue i?ia?aiiu,

eioi?ua caaenyo io eaeeo- eeai yoeo naienoa, yaeyaony /?ac-

au/aeii ia?acoiiui.

sscueii ia oeacuaaaony ii?yaeie au/eneaiey a?aoiaioia ooi-

eoeee; iie au/eneythony ni?aaa iaeaai ia PDP-11 e VAX-11 e

neaaa iai?aai ia inoaeueiuo iaoeiao. ii?yaeie, a eioi?ii i?i-

enoiaeyo iiai/iua yooaeou, oaeaea ia niaoeeoeoee?oaony.

Oae eae neiaieueiua eiinoaiou a aeaenoaeoaeueiinoe yaeythony

iauaeoaie oeia INT, aeiioneaaony eniieueciaaiea neiaieueiuo

eiinoaio, ninoiyueo ec ianeieueeeo neiaieia. Iaeiaei, iineieue-

eo ii?yaeie, a eioi?ii neiaieu i?eienuaathony e neiao, iaiyao-

ny io iaoeiu e iaoeia, eiie?aoiay ?aaeecaoeey ieacuaaaony

aanueia iaoeiii-caaeneiie.

I?enaaeaaiea iieae e neiaai e neiaieia e oeaeui inouanoa-

eyaony ni?aai iaeaai ia PDP-11 e VAX-11 e neaaa iai?aai ia

ae?oaeo iaoeiao. yoe ?acee/ey iacaiaoiu aeey eciee?iaaiiuo

i?ia?aii, a eioi?uo ia ?ac?aoaii niaoeaaoue oeiu (i?aia?acoy,

iai?eia?, oeacaoaeue ia INT a oeacaoaeue ia CHAR e caoai i?i-

aa?yy oeacuaaaioth iaiyoue), ii aeieaeiu o/eouaaoueny i?e niaea-

niaaiee n iaeeaaeuaaaiuie ecaia noaiaie iaiyoe.

· 223 –

sscue, i?eiyoue ia ?acee/iuo eiiieeyoi?ao, ioee/aaony

oieueei iacia/eoaeueiuie aeaoaeyie. Naiia caiaoiia ioee/ea nin-

oieo a oii, /oi eniieuecoaiue a ianoiyuaa a?aiy eiiieeyoi? ia

PDP-11 ia eieoeeaeece?oao no?oeoo?u, eioi?ua niaea?aeao iiey

aeoia, e ia aeiioneaao iaeioi?ua iia?aoeee i?enaaeaaiey a ii-

?aaeaeaiiuo eiioaenoao, naycaiiuo n eniieueciaaieai cia/aiey

i?enaaeaaiey.

25. Aiao?iieciu

Oae eae ycue “C” yaeyaony ?acaeaathueiny ycueii, a noa?uo

i?ia?aiiao iiaeii ano?aoeoue iaeioi?ua onoa?aaoea eiino?oeoeee.

Oioy aieueoeinoai aa?nee eiiieeyoi?a iiaeaea?aeeaaao oaeea aiao-

?iieciu, iie a eiioea eiioeia en/acioo, inoaaea ca niaie oieue-

ei i?iaeaiu ia?aiineiinoe.

A ?aiieo aa?neyo “C” aeey i?iaeai i?enaaeaaiey eniieueci-

aaeanue oi?ia =ON, a ia ON=, i?eaiaey e aeaoniuneaiiinoyi, oe-

ie/iui i?eia?ii eioi?uo yaeyaony

X = -1

aaea X oaeoe/anee oiaiueoaaony, iineieueeo iia?aoeee = e – i?e-

iueatho ae?oa e ae?oao, ii /oi aiieia iiaei ?anniao?eaaoueny e

eae i?enaaeaaiea -1 e X.

Neioaenen eieoeeaeecaoi?ia eciaieeny: ?aiueoa ciae ?aaain-

oaa, n eioi?iai ia/eiaaony eieoeeaeecaoi?, ionoonoaiaae, oae

/oi aianoi

INT X = 1;

eniieueciaaeinue

INT X 1;

eciaiaiea auei aianaii ec-ca eieoeeaeecaoeee

INT F (1+2)

eioi?ay aeinoaoi/ii neeueii iaiiieiaao ii?aaeaeaiea ooieoeee,

/oiau niooeoue eiiieeyoi?u.

26. Naiaeea neioaene/aneeo i?aaee

Yoa naiaeea neioaenena ycuea “C” i?aaeiacia/aia nei?aa aeey

iaeaa/aiey iiieiaiey e ia yaeyaony oi/iie oi?ioee?iaeie ycu-

ea.

26.1. Au?aaeaiey Iniiaiuie au?aaeaieyie yaeythony neaaeothuea:

au?aaeaiea:

ia?ae/iia-au?aaeaiea

· au?aaeaiea

& au?aaeaiea

· au?aaeaiea

! Au?aaeaiea

^ au?aaeaiea

++ L-cia/aiea

· L-cia/aiea

L-cia/aiea ++

L-cia/aiea—

· 224 –

SIZEOF au?aaeaiea

(eiy oeia) au?aaeaiea

au?aaeaiea aeia?iay-iia?aoeey au?aaeaiea

au?aaeaiea ? Au?aaeaiea : au?aaeaiea

L-cia/aiea iia?aoeey-i?enaaeaaiey au?aaeaiea

au?aaeaiea , au?aaeaiea

ia?ae/iia au?aaeaiea:

eaeaioeoeeaoi?

eiinoaioa

no?iea

(au?aaeaiea)

ia?ae/iia-au?aaeaiea (nienie au?aaeaiee

iaia)

ia?ae/iia-au?aaeaiea [au?aaeaiea]

L-cia/aiea . Eaeaioeoeeaoi?

ia?ae/iia au?aaeaiea -> eaeaioeoeeaoi?

L-cia/aiea:

eaeaioeoeeaoi?

ia?ae/iia-au?aaeaiea [au?aaeaiea]

L-cia/aiea . Eaeaioeoeeaoi?

ia?ae/iia-au?aaeaiea -> eaeaioeoeeaoi?

· au?aaeaiea

(L-cia/aiea)

Iia?aoeee ia?ae/iuo au?aaeaiee

() [] . ->

eiatho naiue aunieee i?ei?eoao e a?oiie?othony neaaa

iai?aai. Oia?iua iia?aoeee

· & – ! ^ ++ — SIZEOF(Eiy oeia)

eiatho aieaa ieceee i?ei?eoao, /ai iia?aoeee ia?ae/iuo au?aaea-

iee, ii aieaa aunieee, /ai i?ei?eoao ethaie aeia?iie iia?a-

oeee. Yoe iia?aoeee a?oiie?othony ni?aaa iaeaai. Ana aeia?iua

iia?aoeee e oneiaiay iia?aoeey (i?ei. Ia?aaiae.: oneiaiay iia-

?aoeey a?oiie?oaony ni?aaa iaeaai; yoi eciaiaiea aianaii a

ycue a 1978 a.) a?oiie?othony neaaa iai?aai e eo i?ei?eoao

oauaaao a neaaeothuai ii?yaeea:

Aeia?iua iia?aoeee:

* / %

+ –

>> =

== !=

&

^

!

&&

!!

?:

· 225 –

Ana iia?aoeee i?enaaeaaiey eiatho iaeeiaeiaue i?ei?eoao e a?oi-

ie?othony ni?aaa iaeaai.

Iia?aoeee i?enaaeaaiey:

= += -= *= ?= %= >>=

#IF eiinoaioiia-au?aaeaiea

#IFDEF eaeaioeoeeaoi?

#IFNDEF eaeaioeoeeaoi?

#ELSE

#ENDIF

#LINE eiinoaioa eaeaioeoeeaoi?

Iineaaeiea eciaiaiey ycuea “C” (15 iiya?y 1978 a.)

27. I?enaaeaaiea no?oeoo?u

No?oeoo?u iiaoo auoue i?enaiaiu, ia?aaeaiu ooieoeeyi a ea-

/anoaa a?aoiaioia e aica?auaiu ooieoeeyi. Oeiu o/anoaothueo

iia?aiaeia aeieaeiu inoaaaoueny oaie aea naiuie. Ae?oaea i?aaaeiii-

aeiaiua iia?aoi?u, oaeea eae n?aaiaiea ia ?aaainoai, ia auee

?aaeeciaaiu.

A ?aaeecaoeee aica?auaiey no?oeoo? ooieoeeyie ia PDP-11

eiaaony eiaa?iue aeaoaeo: anee ai a?aiy aica?aoa i?ienoiaeeo

i?a?uaaiea e oa aea naiay ooieoeey iaaioa?aaaeueii aucuaaaony

ai a?aiy yoiai i?a?uaaiey, oi cia/aiea aica?auaaiia ec ia?-

aiai auciaa, iiaeao auoue enii?/aii. Yoa o?oaeiinoue iiaeao aic-

ieeiooue oieueei i?e iaee/ee enoeiiiai i?a?uaaiey, eae ec iia-

?aoeeiiiie nenoaiu, oae e ec i?ia?aiiu iieueciaaoaey, i?a?uaa-

iey, eioi?ia nouanoaaiii aeey eniieueciaaiey neaiaeia; iau/iua

?aeo?neaiua auciau niaa?oaiii aaciianiu.

28. Oei ia?a/eneaiey

Aaaaeai iiaue oei aeaiiuo,aiaeiae/iue neaey?iui oeiai ycu-

ea ianeaeue. E niaoeeoeeaoi?o-oeia a aai neioaene/aneii iiena-

iee a ?acaeaea 8.2. I?eeiaeaiey a neaaeoao aeiaaaeoue

niaoeeoeeaoi?-ia?a/eneaiey

n neioaenenii

iaoeeoeeaoi?-ia?a/eneaiey:

ENUM nienie-ia?a/eneaiey

ENUM eaeaioeoeeaoi? nienie-ia?a/eneaiey

————- ——————-

ENUM eaeaioeoeeaoi?

· 230 –

cienie-ia?a/eneaiey:

ia?a/eneyaiia

nienie-ia?a/eneaiey, ia?a/eneyaiia

——————- ————-

ia?a/eneyaiia:

eaeaioeoeeaoi?

eaeaioeoeeaoi? = eiinoaioiia au?aaeaiea

————- ———————

?ieue eaeaioeoeeaoi?a a niaoeeoeeaoi?a-ia?a/eneaiey iie-

iinoueth aiaeiae/ia ?iee y?euea no?oeoo?u a niaoeeoeeaoi-

?a-no?oeoo?u; eaeaioeoeeaoi? iaicia/aao ii?aaeaeaiiia ia?a/en-

eaiea. Iai?eia?, iienaiea

ENUM COLOR (RED, WHITE, BLACK, BLUE );

. . .

ENUM COLOR *CP, COL;

Iauyaeyao eaeaioeoeeaoi? COLOR y?eueii ia?a/eneaiey oeia,

iienuaathuaai ?acee/iua oeaaoa e caoai iauyaeyao CP oeacaoaeai

ia iauaeo yoiai oeia, a COL – iauaeoii yoiai oeia.

Eaeaioeoeeaoi?u a nienea-ia?a/eneaiey iienuaathony eae

eiinoaiou e iiaoo iiyaeoueny oai, aaea o?aaothony (ii eiioaen-

oo) eiinoaiou. Anee ia eniieuecoaony aoi?ay oi?ia ia?a/eneya-

iiai (n ?aaanoaii =), oi aaee/eiu eiinoaio ia/eiathony n 0 e

aic?anoatho ia 1 a niioaaonoaee n i?i/oaieai eo iienaiey nea-

aa ia i?aai. Ia?a/eneyaiia n i?enaiaieai = i?eaeaao niioaaon-

oaothuaio eaeaioeoeeaoi?o oeacaiioth aaee/eio; iineaaeothuea

eaeaioeoeeaoi?u i?iaeieaeatho i?ia?anneth io i?eienaiiie aaee/e-

iu.

Ana y?euee ia?a/eneaiey e eiinoaiou iiaoo auoue ?acee/iu-

ie e iaiioiaeeie ia y?euee e /eaiu no?oeoo? aeaaea i?e oneiaee

eniieueciaaiey iaeiiai e oiai aea iiiaeanoaa eaeaioeoeeaoi?ia.

Iauaeou aeaiiiai oeia ia?a/eneaiey ?anniao?eaathony eae

iauaeou, eiathuea oei, ioee/iue io ethauo oeiia e eiio?iee?oth-

uay i?ia?aiia LINT niiauaao ia ioeaeao ianiioaaonoaey oeiia.

A ?aaeecaoeee ia PDP-11 ni anaie ia?a/eneyaiuie ia?aiaiiuie

iia?e?otho oae, eae anee au iie eiaee oei INT.

29. Oaaeeoea ecia?aaeaiee iaia/aoiuo neiaieia ycuea “C”.

A aeaiiie oaaeeoea i?eaaaeaiu ecia?aaeaiey iaeioi?uo neiai-

eia (oeao?iua neiaee e o.ae.) ycuea “C”, eioi?uo iiaeao ia

ieacaoueny a ciaeiaii iaai?a aeenieay eee ia/aoathuaai ono?ien-

oaa.

· 231 –

! Cia/aiea ! Ecia?aaeaiea ** !

! ! A oaenoa !

! Oeao?iay ioe?uaathuayny ! !

! Neiaea ! ( !

! ! !

! Oeao?iay cae?uaathuayny ! !

! Neiaea ! ) !

! ! !

! Aa?oeeaeueiay ! !

! *a?oa ! ! !

! ! !

! ! !

! Aiinoi?io ! ‘ !

! ! !

! Aieienoay ! !

! *a?oa ! ^ !

! ! !

** I_?_e_i_a_/_a_i_e_a:

Ecia?aaeaiey i?eaaaeaiu aeey iia?aoeeiiie nenoaiu UNIX. I?e

?aaioa eiiieeyoi?a “C” iiae oi?aaeaieai ethaie ae?oaie iia?aoee-

iiiie nenoaiu, iaiaoiaeeii ainiieueciaaoueny niioaaonoaothuei

?oeiaiaenoaii aeey aeaiiie nenoaiu.

Нашли опечатку? Выделите и нажмите CTRL+Enter

Похожие документы
Обсуждение

Ответить

Курсовые, Дипломы, Рефераты на заказ в кратчайшие сроки
Заказать реферат!
UkrReferat.com. Всі права захищені. 2000-2020