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

SPO5

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

21

/(? 2 ( i 0 / D D 02 -

1.

( " !0 1 / 9 7 6 1 / 6

D 91 9 ( 6 7% 8 6 _findfirst _findnext2, - 0 1 /( 06 /%A? . . -

7 6 *.cpp %? / D.

#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

//# #

1

* / !% ( 6 6-! 7 6, / / " 1 / 9 7 6 1 -

/ 6 .

 

2

( (, " 02 MVS, 1 / 02 7% 8 6 D !0 9 0.

22

ctime_s( szBuffer, _countof(szBuffer), &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 ( , %D 7%-

8 ( ctime_s.

time_t time_write ( / 1 ( 7 6 . k

( 2 ( UTC 7 . ( ! 1 ( , %D 7% 8 ( ctime_s.

fsize_t size 1 7 6 ! 6 2

_MAX_PATH / Stdlib.h 260 ! 6.

UTC ( (Coordinated Universal Time) (?

( " 9A 0 ( )- "%(GMT). " 9A / % /0 1 " )- "% (GMT) " 9 % / % -

" (UTC).

( ! 1 ( UTC %A % %D 7% 8 ( c_times, A? ( :

 

23

errno_t ctime_s(

 

char* buffer,

!%7, 06 !%/ 1 (

size_t numberOfElements, 1 !%7 ! 6 2

const time_t *time

( 7 UTC

);

 

. attrib i ! 8 ( !% 7 6 , 0

91%A ( . . attrib D A" 9 /%A- ? / 0 7 6 io.h 0:

_A_ARCH 2 06 7 6

_A_HIDDEN 0 06 7 6

_A_NORMAL 7 6 2 / % 2 ! -

!% D " 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 A

?9A % 2 1 . ( i !2 /, " !0 7% 8 ( / % % 9 %,

1 / ( / ( 7 6. . i - !2 / 0 9 / 6 (:

1)C 1 9 % 1 2

2 / ;

2)( D/ / 01 9 7% 8 A 1-

0 %, A" A? ( ! ! 0 ;

3)C 1 9 7 6 .

. i 7% 8 ( !%/ 9 /:

int SumFiles = 0; using namespace std;

bool FindFile(char *Path, char *Mask)

{

struct _finddata_t findData; intptr_t hFile;

24

char FullName1[_MAX_PATH];

//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");

25

FindFile("C:\\Windows", "*.bmp");

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

_getch(); return 0;

}

; ! % K 6 6 D / 9 ! 7 6,

/ ( 6 !2 / %A 7 8 A ?9A / 6

.

( / " 7% 8 A _tmain 91%A ( / -

, 06 %D / ( / " " / - 02 , 6 / ( / " 2 . C!? ( 0 (

!(1 9 0) i 2 argc argv. . argc

int, 1 " 7 % ( 1 1 / 6 -

" % / 6 , A" ( ( 0- 10 6 0. . argv i % 1 6 -

( _TCHAR), D/ ( 1 02 / D / 1 -/ 6 . z / D / D 9 !,

1 / %A % / D !0 9 1 A"

0".

.% 9 1 7% 8 _tmain 0 FindFile

/:

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

+ / , / ( 0 FindFile 1 - /%A? ! 1:

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

% 0 argc, argv / (A ( ( :

argc: 3

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

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

+ _TCHAR i Unicode. z 0 ! 9 91 9

0 / 6 , , " !0 1 9 ( /-

26

, ? 6 6 0K % FindFile Solution Explorer – FindFile. ( K ( A 0!-

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

2.3. " J 2 > ?

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

%, ( 0 ( /%A? / 6 (:

1) 0 / 1 ( 2 7 6, %/ (A? 2 , % 1 - 6 / 6 ;

2) 0 / 2 7 6, A? 2 1 9 K2 /(? 2 ( 1 9 6 D 02 2.

2.4. / ?7 2 > ?

1. ; 1 ! 9 / 0.

2. F ! 9 / 0.

3. .1 / % 0.

4. ./ 9 " 0 ! 0.

2.5. > 2 J 28 1

 

C " ! 6 ! 7 ( ( / /% 9 D-

/0 %/ / D / D 9:

1)

1 ! 6 0;

2)

1% 9 0 ! 0 0 / ( , / D ? 2

 

06 % 9 7 6 , 9 06 % 9.

27

3., .3. / 2 5 7 3-. 2

3.1.( > 4 > ?

= 9A (? 6 ! 6 ! 0 ( ( (

0 % (/ " / ( / 02 7 6 2, 2- /(? 2 ( %? 6 D 02 2. (/ " / D 0 ( 9 ( , 1 % / 1/ ( 1 - D 6 91 (.

3.2.21 1

@%, D !0 9 ( 1 ! 6 - ! 0 „2 0 % K (. C" /, " / ( 0 ( % (/ " (, 6/ 0 7 6 0 / 9 - !2 / 1 9 ( 9. / 9 i ? , 91%(

, i D %D 9 % % :

struct DItem

{

// , ! ? ! =?

struct _finddata_t findData; DItem *prev, *next;

};

( ! 0 !2 / 0 /%A? 7% 8:

//>! #= ƒ

DItem* CreateItem();

//f # #= ƒ # •

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

//’! ƒ

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

 

28

 

. 06 0 D 0 (/ 9, , /%A? ! 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 A FindFile(), 0 0 / - 7 8 6/ 02 7 6 2 !2 / 1 9 , 1/ A? 06 i , 1 01 9 7% 8 Add(),

( / ! 9 1/ 06 i . F i i

29

D 0 9 / " 6/ 02 7 6. *2 " - / ! ( / ( 1/ ( / " .

0 9 % i / 9 D

? 0 9 / 02 06 , 1 " 9 7 % 06 06. @ / " 1 " 9 ! " (,

/ D 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;

}

b % % 9 1 " 9 ?. i 6 8 9A D 91 9 0 1 " 0 /0 (/ ( 6 -

, / %10 9 , / … , K 6 %A % . /.).

30

b0 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 A ( A- ?%A :

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

* ( 7% 8 ( D !0 9 1 9 0 0!-

( 91 .

.% 9 1 / % % , 2 (? ( 7 8 A " / :

struct POINT

{

//o ! = x, y, z

double x; double y; double z;

//! #=

int number;

};

( 2 % % 1 A - / 0 y, D %D 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;

 

 

}

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