WWW.DISSERS.RU


...
    !

Pages:     | 1 |   ...   | 8 | 9 || 11 | 12 |   ...   | 21 |

1 Bcec paee. ae, ec ece poo, peypyeo apyea cpaaec c o cooecyeo opaoo apaepa. Ec o e coaa, o o pooc peopaoae o, o aec aocecoe cooee. co pae cce pae oo coaa c co opax apaepo. Ec pooe y eco cca opax apaepo aao eoe coo void, o oaae, o y e epeaec ax apaepo, opeee y e oo opax apaepo.

2 pocxo aea opax apaepo a aece.

3 paee epeaec a ep oepaop y.

4 Boee oepaopa return opaae ypaee ooo aee ay y. Ec oepaop return e aa, o, oce oe oceeo oepaopa ea y, ypaee opaaec oy oa.

puep epea acca y a apaep:

#include int data[2][2]={-12, 14, -10, 16};

main () { extern void modify (int *a, int size);

int i;

//modify (data, 4);

for (i=0;i<4;i++) printf (" \ndata[%d]=%d\n", i, * (data+1));

} void modify (int *a, int size) { int i;

for (i=0;i

} puep epea acca y o ae.

#include #define size void main (void) { int mas[size];

int i, j;

printf ("\n max=%d", max (mas, size));

printf ("\n min=%d", min (mas, size));

} int max (int data[], int s) } int maximum=data[0];

int i, j;

for (i=0;imaximum) maximum=data[i];

return (maximum);

} int min (int data[], int s) { int minimum=data[0];

int i, j;

for (i=0;i

return (minimum);

} p aa acca aece apaepa y epeaec apec epoo eea acca. Ec ee y aec ae eeo acca, o ec eocpeceo ca epeaae acc.

Ec oca y aao, o apaep epeaec o cce (.e. o oca a yaae a ), o aece apaepa p oe y epeaec apec epeeo.

P e y p c e o a y a ax C aca oe aa peypco, o ec oa oe a cay ce.

oop oycae oe co peypcx oo. p ao oe, opax apaepo (epeea c acco auto (pae 5.11.1)), eec oa a. Ta opao, x aee peecyx peypcx oo e apaec. apaep peecyx eaepex oo eocy. epeee, oee acco a static, e pey oo a.

accuecu npuep peypcuu o aeaecoe opeeee aopaa = = - > long fact (int n) { return (n<=1)1:n*fact (n-1);

} puep cooa ycoo oepaopa:

int lin (char*str) { int index = 0;

while (str[index++]) ;

return (index);} Cmu npopaupoau: peoeyec (;), oocyc ycoy oepaopy, oea a oeo cpoe ae p e popa oo e opa ae a yco oepaop.

a o o- o a C C e coep cpec oep oa/oa. aa peaa C oa copooac oea apoca, ocya o/o. o epe pa C y oa/oa caoc caappoa. Taa caapa oecea co ypoe ooc popa a C.

Tep "oo" pocxo pecae o oceoaeo cpyype opaox ace. Coca ooa aaec cpyypo FILE, ocae oopo aaec ae stdio.h.

Mapoc EOF opeeec cey opao:

#define EOF (-1) O oepax oa/oa cy ooae poep oa aa.

y fopen coyec op ooa (aa). epec c ye fopen ocaec cey opao:

FILE fopen (char filename, char type);

B aece epoo apaepa y oo epeaac paoe aa.

Bopo apaep opeee opaeoo aa.

oyc ceye ao:

"r" op ye cyecy a a o;

"w" coa o a oc ye cyecy a op eo a o;

"a" coa o a oa ocyec o oe ye cyecyeo aa;

"r+" op cyecy a ooe, oopoe ye pooc c aaa aa;

"w+" coa o op cyecy a ooe eo coepoo;

"a+" coa o a ocpoc oe cyecyeo aa ooe eo coepoo.

y flclose cey opao:

int fclose (FILE *stream);

C oo o y a apaec.

y fseek ocaec cey opao:

int fseek (FILE *stream, long offset, int wherefrom);.

a y cy poooo ocya aa, oo yp ox ooo.

ep apye aae oo, oopoy oe ocyecc po ocy.

Bopo apye yaae co a cee o o, opeeeo pe apaepo y.

Tpe apaep yaae oy, o oopo ceye aa oce cee, aaoo op apyeo.

aee 0 ceee o aaa aa.

aee 1 ceee o eye o aa.

aee 2 ceee o oa aa.

pep popa a C: Coppoa a eoopx ce. aca o opo a oeco ooex, opaex yex eeo epoo aa.

// oaee oe #include // oea oa-oa #include // oea pao c oa #define N 6 // Mapoopeeee (paepoc acca) void main (void) // aa y (ocoo o popa) { // Pae oe oax epeex FILE *f1; // aae a ep a FILE *f2; // aae a opo a int mas[N]; // Macc, eea oopoo aoec ep a int i, buf, nul, otr, pol; // i epeea cea a // buf epeea, oopy yy cac ae epoo aa // nul, otr, pol epeee oeca ooex, opaex yex //eeo epoo aa cooeceo clrscr (); // Oca paa printf ("Cocae: Hoae Mac epo");

printf ("\n\t\t aye T, pya P-12 \n\n"); // aoee acca for (i=0; i

scanf ("%i", &mas[i]); // Bo eeo acca } // Coae eye aaoe ao c ea file1 file// ope x a ac f1=fopen ("file1", "w+");

f2=fopen ("file2", "w+");

// ac a c ee file1 eeo acca mas[N] for (i=0; i

fclose (f1); // ape aa filepol=0; // pcoee aaoo ae epee otr=0; // oeca ooex, opaex nul=0; // yex eeo // Ope aa c ee file1 a ee fopen ("file1", "r+");

// ee aa opa epeey buf o ex op, // oa e acy oe aa while (fread (&buf, sizeof (int), 1, f1)!=0) { // Ec oepeoe aee epeeo buf ooeoe, o // aee epeeo pol yeaec a if (buf>0) pol=pol+1;

// Ec oepeoe aee epeeo buf opaeoe, o // aee epeeo otr yeaec a if (buf<0) otr=otr+1;

// Ec oepeoe aee epeeo buf pao y, o // aee epeeo nul yeaec a if (buf==0) nul=nul+1;

} // ac a file2 oeca ooex, opaex // yex eeo epoo aa filefprintf (f2,"B EPBOM AE COEPTC:\n");

fprintf (f2, "\n ooex eeo: %i", pol);

fprintf (f2, "\n opaex eeo: %i", otr);

fprintf (f2, "\n yex eeo: %i", nul);

// Bo cooe o aepe pao popa printf ("PAOTA C AAM ABEPEHA");

printf ("\n Hae y ay");

getch (); // aepa paa o aa o a } a a c ae aoa epeea acae o a epeea aooo a. B acae ec p acca ao: poa, eco, epoa.

epe cooae aoo epeeo oa oa caa c e ao c oo oa poeyp Assign. Be ao oo ec oeoa a a ce, o o ae oe peca coo ycpoco, a apep, aaypy ce. Bo ex aax coxpaec acaa a opa o cya coa opa, oopa caec aa.

puep:

Const Path = a:\MyDir;

Var MqFile: File of Integer;

Temp : string.

Begin Assing (MyFile, a:\MyDir\Data.dat);

Assing (MyFile, Path+Data.dat);

Reset (MyFile);

if IoResult=0 then Writeln (a oo paoe) Else Writeln (eepo aao aa);

Apprend (MyFile); {ec e cyecye o coaec} While not SeekEOF Do Begin Readln (Temp);{cae cpo c aayp} Writeln (MyFile, Temp); {ac cpo a.} end;

close (MyFile);

reset (MyFile);

While not SeekEOF Do Begin Readln (MyFile, Temp); {cae cpo aa} Writeln (Temp); {o cpo a ce} end;

close (MyFile);

end.

oa c c e ao ycaoea, ooo ee oepa oa oa aoa epeea oa "opa". Cyecy a oo op c oo poeyp Reset, a o a oo coa op c oo poeyp Rewrite. Tecoe a, ope c oo poeyp Reset, ocy oo e, a mecmoe a, ope c oo poeyp Rewrite Append, ocy oo ac.

Tpoae epoae a cea oyca a ee, a ac, eaco o oo, o op c oo poeyp Reset c oo poeyp Rewrite.

o a pecae coo ey oceoaeoc eeo, a oopx ee co ( ac) aa. a ee aa ee oep. ep ee aa caec ye eeo.

Oo ocy aa opayec oceoaeo, o ec, oa ee caec c oo caapo poeyp Read acaec c oo caapo poeyp Write, eya o aa epeeaec ceyey o opy eey aa. Oao poa epoa aa oo opaoa po ocy c oo caapo poeyp Seek, oopa epeeae eyy o aa aaoy eey. Teyy o ae ey paep aa oo opee c oo caapx y FilePos FileSize.

puep paom c munuupoau aau poo ocy Var MyFile: File of Integer;

I, K, Temp: Integer;

Begin Assiqn (MyFile; data.dat);

ReWrite (MyFile);

for I:=1 to 5 Do Begin Write (MyFile, I); {ac ca ae} for k: =I-1downto 0 Do Begin Seek (MyFile, K); {epeycaoa yaae aa} Read (MyFile, Temp); {cae} end;

Seek (MyFile, I); {occaoee yaae aa} end;

Close (MyFile);

end;

Peya pao popa acaec a data.dat 121321432154321.

Paoa popa o aa.

i=1 k=0 i=2 k=1 k=0 i=3 k=2 k=1 k=0 1 ...

oa popaa aep opaoy aa, o oe apac c oo caapo poeyp Close. oce ooo ap aa, ca c e a ooec. ae aoa epeea oe caa c py e ao.

o yoa, p cex opaex caap y poeypa oa/oa aoaec pooc poepa a ae oo. p oapye o popaa pepaae paoy o a pa cooee o oe. C oo pe oopa {$I+} {$I-} y aoaecy poepy oo . oa aoaeca poepa oea, o ec oa poeypa y a copoaa c peo {$I-}, o oa/oa, oae p paoe popa, e po ee ocaoy. p o, o poep peya oe oepa oa/oa, yo cooa caapy y IOResult (a. 17, 18).

17 POEP BBOA/BBOA Haeoae HA HAEHE ChDir Mee ey cpao Erase ae e a Bopaae ey cpao a aao GetDir ce MkDir Coae ocpao Reset Opae cyecy a Rewrite Coae opae o a RmDir ae yco ocpao epeae eyy o aa a Seek yaay ooey (e coyec c eco aa) ceae paep aa o eye o Truncate ae. (He coyec c eco aa) 18 H BBOA/ BBOA Haeoae Haaee Eof y EOF opaae peya TRUE FALSE acoc o oce oa aa ooy oe cooaa ycox paex.

FilePos Bopaae eyy o ae.

(He coyec c eco aa) FileSize Bopaae ey paep aa.

(He coyec c eco aa) IOResult Bopaae eoe aee, eec cocoe ocee oeo oepa oa/oa.

P MEP :

Coppoa a eoopx ce. aca o opo a oeco ooex, opaex yex eeo aa.

uses CRT; {oee oe oa-oa} const n=10; {Maca paep acca} {Pae oe epeex} var File1, File2: FILE of Integer; {epeee aooo a} Road1, Road2: String[14]; {Cpo xpae e ao} a : Array[1..n] of Integer; {Macc xpae eex ce} i, pol, otr, nul: Integer; {i-ce a} {pol oeco ooex eeo acca} {otr oeco opaex eeo acca} {nul oeco yex eeo acca} {Ocoo o popa} begin ClrScr; {Oca paa} WriteLn ('Bo Hoae M.., T, p. P-12');

Road1:='Test1.dat'; {aae e ao} Road2:='Test2.dat';

Assign (File1, Road1); {C aoo epeeo c e ao Road1} Rewrite (File1); {Coae ope aa Test1.dat} Assign (File2, Road2); {C aoo epeeo c e ao Road2} Rewrite (File2); {Coae ope aa Test2.dat} pol:=0; {aa epeex} otr:=0;

nul:=0;

for i:=1 to n do begin WriteLn ('Bee ', i, ' ee acca'); {apoc y ooae eeo acca} Read (a[i]); {Bo eeo acca} Write (File1, a[i]); {ac x a Test1.dat} end;

Close (File1); {ape aa Test1.dat} WriteLn; {poyc cpo} WriteLn ('');

Pages:     | 1 |   ...   | 8 | 9 || 11 | 12 |   ...   | 21 |



2011 www.dissers.ru -

, .
, , , , 1-2 .