Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

СПО_Praktikum_k_lab_rabotam

.pdf
Скачиваний:
8
Добавлен:
16.05.2015
Размер:
1.26 Mб
Скачать

21

/)? 2 ) G ! ! 0 / B B 02 ! !-1.

) # "0 1 / 9 7!6 1!/! 6 ! B 91 ! 9 ) ! 6 7& 8 6 _findfirst _findnext2, - 0 1 /) 06 /&<? . . -

! 7!6 *.cpp &? ! ! / ! B.

#include "stdafx.h" #include "conio.h" #include "stdlib.h" #include "io.h"

#include "time.h" #include "cstringt.h" #include "iostream" #include "iomanip"

#define LIM_STR 255

int _tmain(int argc, _TCHAR* argv[])

{

setlocale(LC_CTYPE, "Russian_Russia.1251"); char szBuffer[LIM_STR];

struct _finddata_t findData; intptr_t hFile;

//# g cpp # P

//!

if( (hFile = _findfirst( "*.cpp", &findData )) == -1L )

cout << "Π= *.cpp # P ! #!"; cout << endl;

else

{

cout << "Π= *.cpp" << endl << endl; cout << setw(18) << "" ";

cout << setw(28) << "‚ >!"; cout << setw(12) << "• >";

cout << setw(12) << "Ž ="<<endl << endl; do

{

//> # # # UTC

//# #

ctime_s( szBuffer, _countof(szBuffer),

1+ /! "& ) !6 ! 6-" 7!6, /! / ! # 1 / 9 7!6 1!-

/! 6 !.

2) ), # 02 MVS, !1 ! /! 02 7& 8 6 B "0 9 0.

22

&findData.time_write ); szBuffer[strlen(szBuffer)-1] = NULL; cout << setw(18) << findData.name; cout << setw(28) << szBuffer;

cout << setw(12) << findData.size << " "; cout << setfill(' ') << setw(8); findData.attrib & _A_RDONLY ?

cout << "r" : cout << "-"; findData.attrib & _A_HIDDEN ?

cout << "h" : cout << "-"; findData.attrib & _A_SYSTEM ?

cout << "s" : cout << "-"; findData.attrib & _A_ARCH ?

cout << "a" : cout << "-"; cout << endl;

} while( _findnext( hFile, &findData ) == 0 );

_findclose( hFile );

}

_getch(); return 0;

}

unsigned attrib ! "& 0 7!6 !.

time_t time_create ) 1/! ) 7!6 !. K ) 2 ! )UTC 7 !. ) " !1 ! ) , &B 7&-

8 ) ctime_s.

time_t time_write ) / 1 ) 7!6 !. K

) 2 ! ) UTC 7 !. ) " !1 ! ) , &B 7& 8 ) ctime_s.

fsize_t size !1 7!6 ! "!6 !2

_MAX_PATH / Stdlib.h ! 260 "!6.

UTC ) (Coordinated Universal Time) ! )?

) ! # 9< 0 ) *- #&(GMT). # 9< / & /0 1 !# *- #& (GMT) ! "! 9 & / ! & -

" (UTC).

) " !1 ! ) UTC &< & &B 7& 8 ) c_times, <?!) :

errno_t ctime_s(

 

23

char* buffer,

"&7, 06 "&/ 1! ! )

size_t numberOfElements, !1 "&7 ! "!6 !2

const time_t *time

) 7 ! UTC

);

.! ! attrib G " !8 ) ! "& 7!6 !, 0

91&< ) . .! ! attrib B <#! 9 /&<- ? / 0 7!6 io.h ! 0:

_A_ARCH ! 2 06 7!6

_A_HIDDEN 0 06 7!6

_A_NORMAL 7!6 ! 2 / & 2 !" !- "& B # ! 9 ) 1! 0 ! 9 ) " 1 ! # 6.

_A_RDONLY 7!6 9 / ) # )

_A_SUBDIR

! !

_A_SYSTEM

06 7!6

) # "0 ! 1 ! 9 " !" & /! 02, ! 1 !- 02 ! 2 # & 8 &, "2 / ! 1 ! 9 7& 8 <

! ?9< & 2! 1 !. ) G "2 /, # "0 7& 8 ) ! ! ! / ! ! & ! & 9 ! ! &,

1 / ) ! ! / ) 7!6. . G - "2 / 0 9 / 6 ):

1)A ! 1 ! 9 & !1! ! ! !2 ! !

2 / ! ! ;

2)) !B/ / ! ! ! 01 ! 9 7& 8 < ! 1-

0 &, <#!<? ) " !"! 0 ! ! ! !;

3)A ! 1 ! 9 7!6 !.

. G 7& 8 ) ! "&/ 9 /:

int SumFiles = 0; using namespace std;

bool FindFile(char *Path, char *Mask)

{

struct _finddata_t findData; intptr_t hFile;

char FullName1[_MAX_PATH];

24

//xfy z c ! # ? #,

//ƒ > # FullName1.

//!

if( (hFile = _findfirst( FullName1, &findData )) != -1L ) do

{

if( findData.attrib == _A_SUBDIR && (_strcmpi(findData.name, ".") && _strcmpi(findData.name, "..")))

{

char NextPath[_MAX_PATH];

//xfy z c !

//# ? # # ! , ƒ

//> # NextPath.

//• # = #=> # FindFile FindFile(NextPath, Mask);

}

} while (_findnext( hFile, &findData ) == 0); _findclose( hFile );

char FullName2[_MAX_PATH];

//xfy z c !

//# ? # # P > ! ,

//! ĥ # FullName2.

//# # P !

if( (hFile = _findfirst( FullName2, &findData )) == -1L ) return true;

do

{

SumFiles++;

// ! # ! =?

//#

//‚=# ! ƒ ! =? ?. cout << "File = " << findData.name << endl;

}while (_findnext( hFile, &findData ) == 0);

_findclose( hFile );

return true;

}

////////////////////////////////////////////////////////////////

//

int _tmain(int argc, _TCHAR* argv[])

{

setlocale(LC_CTYPE, "Russian_Russia.1251"); FindFile("C:\\Windows", "*.bmp");

cout << "• > . | ! #: ";

25

cout << SumFiles << endl; _getch();

return 0;

}

N!" & !D 6 ! 6 B / ! 9 " 7 6,

/! !) 6 "2 / &< 7 !8 < ?9< ! / 6

.

) /!# 7& 8 < _tmain 91&< ) / ! ! !-

!, 06 ! ! &B / ) /!# # ! /! !- 02 , 6 / ) /!# ! 2 . A"? ) 0 (

")1! 9 0) ! G 2 ! ! argc argv. .! ! argc

int, 1 !# 7 & ) 1 ! ! 1! ! / 6 -

! # & ! / 6 , <#!) ) 0- 10 ! 6 ! 0. .! ! argv G ! & !1! 6 ! -

( _TCHAR), !B/!) 1 02 / B / 1 - ! / 6 . m / B / B! 9 ",

1! ! / &< & / B "0 9 1! <# ! 0#.

.& 9 1! 7& 8 _tmain ! 0 FindFile

/:

int _tmain(int argc, _TCHAR* argv[])

, /!, ! / !) ! ! 0 FindFile 1! ! ! - /&<? " !1:

D:\MyProg>FindFile.exe C:\ *.cpp

! & 0 argc, argv / ! )< ) ! ) !:

argc: 3

argv[0]: «D:\MyProg\FindFile.exe» argv[1]: «C:\»

argv[2]: «*.cpp» argv[3]: NULL

, _TCHAR G Unicode. m 0 " ! 9 91 ! 9

! ! 0 ! / 6 , , # "0 1! ! 9 ) /- !, ? ! 6 6 0D & FindFile So-

26

lution Explorer – FindFile. ) D ) < 0"-

Properties. 6 Configuration Properties 0" General. .! ! Character Set & ! Use Multi-byte Character Set.

2.3. F I2- 2< .=

. 0 !" 0 "2 / !1 !" ! 9, !" ! 9 !/ 9

! &, !) 0 ) /&<? / 6 ):

1)0 / !1 ! ) 2 7!6, &/ )<? 2 !, & !1!- 6 ! / 6 ;

2)0 / 2 7!6, <? 2 1 9 ! D !2 /)? 2 ) 1 9 6 ! B 02 ! !2.

2.4. * F =4- 2< .=

1.N!1 !" ! 9 / ! 0.

2.F!" ! 9 / ! 0.

3. .1 !/ & ! 0.

4. ./ 9 # 0 !" 0.

2.5. < 2- F I2-6 ., .2

A # !" ! 6 !" 7 ) ) / /&! 9 !B- /0 &/ / B / B! 9:

1)!1 !" ! 6 ! 0;

2)1& 9 ! 0 !" 0 ! 0 / ) ! !, / B!? 2 ! 06 & 9 7!6 !, ! 9 06 & 9.

27

3.& )3. *- 12 4 /2. '2 .5 2

3.1.! 5 2< 2. 0 2< .=

> 9< ! )? 6 !" ! 6 !" 0 ) ) ) ! !

! 0 & )/ # / ! ) /! 02 7!6 !2, !2- /)? 2 ) &? 6 B 02 ! !2. )/ # ! / B 0 ) 9 ) , !1 & /! 1/! ) 1! - B ! 6 91 ! ).

3.2. .-, 2 ,2 .5

@! &, B "0 9 ) ! ! ! 1 !" ! 6 !- " 0 •2 0 & D ! ). A# /, # / ) 0 ) & )/ # ! ), !6/ 0 7!6 0 / ! 9 - "2 / 1! 9 ! ) 9. / ! 9 G ? , 91&)

, G B &B 9 & & !:

struct DItem

{

// , ! ? ! =?

struct _finddata_t findData; DItem *prev, *next;

};

) !" 0 ! "2 / 0 /&<? 7& 8:

//>! #= ƒ

DItem* CreateItem();

//f # #= ƒ # •

void Add(DItem *end, DItem *NewElem);

//’! ƒ

void Delete(DItem *end, DItem *NewElem);

 

28

 

. 06 ! ! ! 0 B 0 )/ 9, , /&<? " !1:

// % = =

// #= ƒ

DItem *g_Head = NULL;

int _tmain(int argc, _TCHAR* argv[])

 

{

 

 

char Path[] = "C:\\Windows\\";

 

char Mask[] = "*.bmp";

 

… …

 

 

g_Head = FimdFile(Path, Mask);

// # = #

 

 

// !

//xfy z … = #=# ! ƒ

//! … • ! • .

… …

return 0;

}

DItem* FimdFile(char *Path, char *Mask)

{

}

DItem* CreateItem()

{

}

void Add(DItem *end, DItem *NewElem)

{

}

void Delete(DItem *end, DItem *NewElem)

{

}

& 6 7& 8 < FindFile(), ! 0 0 /! - 7 !8 !6/ 02 7!6 !2 "2 / 1! 9 ! !, 1/!<? 06 G !, ! 1! 01 ! 9 7& 8 Add(),

!) / "! 9 1/! 06 G . F! G G !

29

B 0 9 / # !6/ 02 7!6. +2 # !- / " ) / ) 1/! ) / ! # ! !.

0 9 & G ! / 9 B

? 0 9 ! /! 02 06 , 1 !#! 9 7 & 06 ! ! 06. @!/!#! 1 !# 9 " #! ),

/ B ! 1! / ! # 1/! 06 !

! _finddata_t. M& 8 ) _tmain() /:

int _tmain(int argc, _TCHAR* argv[])

{

DItem *Curr, *Old;

struct _finddata_t *findData; char Path[] = "C:\\Windows\\"; char Mask[] = "*.bmp";

g_SumFile = 0;

//

g_Head = FimdFile(Path, Mask);

// ! =? #

// # = #

 

// !

//xfy z … = #=# ! ƒ

//! … • ! • .

//f #=! ! #

findData = new _finddata_t[g_SumFile];

//xfy z … ! =# P ! …

//# ! #=! = # findData

//. " # #

//findData. xfy z … ! ! P #g … =

//.

//xfy z, !, … = #=# !

//ƒ ! … • ! • >

//# findData.

_getch();

delete[] findData; // # …!

return 0;

}

E! & & ! 9 1 !# 9 ?. G 6 8 9< B 91 ! 9 ! 0 !1 # 0 /0 (/ ) 6 -

, / &10 9 !, / ‚ !, D 6 &< & . /.).

30

E0 91& ) ! /! 6 7& 8 6 qsort(), -

6 /:

void qsort(

// ! # •

ƒ #

void *base,

size_t num,

// ( void)

 

// # ƒ#

size_t width,

// > ! •

ƒ

int (__cdecl *compare )(const void*, const void*)

);

& compare & !1! 9 ! 7& 8 < ! ) <- ?&< :

compare( (void*) &elem1, (void*) &elem2 );

+ ) 7& 8 ! ) B "0 9 1 9 0 0"- ! ) 91 !.

.& 9 1!/! ! & & !, 2 ! )?!) 7 !8 < # /!:

struct POINT

{

//o ! = x, y, z

double x; double y; double z;

//! #=

int number;

};

) ! ! ! 2 & & 1 ! ! < - / ! 0 y, B &B 9 7& 8 ) ! ):

int ComparePtY(const void *arg1, const void *arg2)

{

POINT *pt1 = (POINT*)arg1; POINT *pt2 = (POINT*)arg2;

double a = pt1->y -

pt2->y;

if(a<0)

return

-1;

else if(a>0) return

1;

return 0;

 

 

}

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]