+ All Categories
Home > Documents > 1. 2 C/C++ Text File Functions fopen opens a text file. fclose closes a text file. feof ...

1. 2 C/C++ Text File Functions fopen opens a text file. fclose closes a text file. feof ...

Date post: 18-Jan-2018
Category:
Upload: amice-margery-cameron
View: 232 times
Download: 0 times
Share this document with a friend
Description:
C/C++ Text File Functions  fopen – opens a text file.  fclose – closes a text file.  feof – detects end-of-file marker in a file.  fscanf – reads formatted input from a file.  fprintf – prints formatted output to a file.  fgets – reads a string from a file.  fputs – prints a string to a file.  fgetc – reads a character from a file.  fputc – prints a character to a file.  fflush – empties the buffer 3
182
1
Transcript
Page 1: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

1

Page 2: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

2

Page 3: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

C/C++ Text File Functions

fopen – opens a text file.

fclose – closes a text file.

feof – detects end-of-file marker in a file.

fscanf – reads formatted input from a file.

fprintf – prints formatted output to a file.

fgets – reads a string from a file.

fputs – prints a string to a file.

fgetc – reads a character from a file.

fputc – prints a character to a file.

fflush – empties the buffer3

Page 4: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Review Practice 1

If You Are NotComfortable

With Doing ThisPractice It! 4

Page 5: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Review Practice 2

If You Are NotComfortable

With Doing ThisPractice It!

5

Page 6: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Standard Text Files - Program A

Mode “w” erases, the file if it exits!

If You Are NotComfortable With

Doing This Practice It!

6

Page 7: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Read From Text File

If You Are NotComfortable

With Doing ThisPractice It!

7

Page 8: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

8

Page 9: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

9

Page 11: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

11

Page 12: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

12

Some Applications Require More Than 24 Hours To Read A Single

File!12

Page 13: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

13

Some Applications Require More Than 24 Hours To Read

A Single File!

Text File Read ProcessingOpen FileRead & Write To Sought DataRepeat!

Sought Data

Sought Data

Read #1 Read #2

ReadRead

13

Page 14: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

14

Some Applications Require More Than 24 Hours To Read A Single

File!14

Page 15: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Text File Change ProcessingOpen Original & Destination FilesRead Original – Write Destination [up to point of change]Write Change DataRead Original – Write Destination [remaining data]Erase Original File & Rename Destination File

Change Data

Change #1

Read &

Write

15

Changed Data

Read & Write

Page 16: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

16

Page 17: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

17

Can Often Be Done In Less Than 1/10 Second

Hardware Dependent

DA File Read ProcessingOpen File

Seek & Read DataRepeat!

Sought Data

Sought Data

Read #1 Read #217

Page 18: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

DA Change ProcessingOpen Original

Read Original – Write Destination [up to point of change]Write Change Data

Change Data

Change #1

Read

Make Change

Write

18

Page 19: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

19

Page 20: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

20

Page 21: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Text Files

Direct Access Files

The Choice Is Yours!

21

Page 22: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

22

Page 23: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Create Three New Direct Access Files

Close File

File Ptrs

23Execute This Program?

Create File

23

Page 24: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

What Happened As A Result Of Executing This Program?

Three Files Were Created? Where? Find Them!

24

Page 25: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

How Big Are The Files? How Do You Know?Right Mouse Click on the file and select Properties!

25

Page 26: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

26

Dir ls

26

Page 27: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

27

Dir *.fil ls *.fil

Dir Wild Cards *

Page 28: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

28

StudentFil = fopen("Student.Fil", "wb+");

Opening a file in the wb+ mode checks to see if there is a file by the name Student.Fil:

If so, it erases the contents & positions the read/write pointer at the beginning of the empty file

If not, it creates the file & positions the read/write pointer at the beginning of the empty file

About fopen

Page 29: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

fopen Modes

Direct Access Files DAF’s

29

Page 30: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

30

fclose(StudentFil);• All files are buffered. • The buffer size can be set by the operating

system and or the programming language. • To reduce wear and tear on the hard drives, most

operating systems write information to a buffer – when the buffer is full, it is dumped to disk.

• When a file is closed, the information, remaining in the buffer, is written to disk and the file allocation table is updated to reflect changes in the file.

• Failure to close a file can result in lost information.

About fclose

Page 31: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

31

Page 32: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

32

About fseekfseek(FilePtr, NoBytes, SEEK_SET);

SEEK_SET is a constant representing the beginning of the file. SEEK_END is a constant representing the end of the file.

fseek(StudentFil, 4 * sizeof(Student), SEEK_SET);

The size of each Student record is 36 Bytes.

Move the Read-Write Pointer 4 * 36 = 144 bytes from the beginning of the file referenced by the StudentFil ptr.

Valid Records To Seek Are 0 – N+1

Page 33: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

33

fseek(StudentFil, 0 * sizeof(Student), SEEK_SET);fseek(StudentFil, 0, SEEK_SET);

Move the Read-Write Pointer to the beginning of the file [First Record]

fseek(StudentFil, (N+1) * sizeof(Student), SEEK_SET);fseek(StudentFil, 0 * sizeof(Student), SEEK_END);

fseek(StudentFil, 0, SEEK_END);

Move the Read-Write Pointer to the end of the file [EOF Marker] – to append a new record.

fseek Examples

Page 34: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

34

Page 35: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

35

fwrite(&Info, InfoSize(byes), # records, fp);fwrite(&NewStudent, sizeof(Student),(long)1,StudentFil);

Write the 1 record of information referenced by NewStudent, whose size is 36 Bytes, to the current Read-Write Location of the StudentFil.

Student Students[20]fwrite(&Students,sizeof(Student),(long)20,StudentFil);

Write the 20 records of information referenced by array Students to the current Read-Write Location of the StudentFil.

FWRITE can be used to write a single record or a block of records.

About fwrite

Page 36: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Suppose the Output Buffer holds only two records.Student LocalYear;fseek(StudentFil, 3 * sizeof(Student), SEEK_SET);

fwrite(&LocalYear,sizeof(Student),(long)1,StudentFil);

36

The information is actually written to the buffer – when the buffer is full or location is changed, it is written to disk. The buffer size can be set 0 to force immediate writes!

fwrite Examples

Page 37: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

37

Page 38: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Review -Valid Writes For A File With 3 Records Replace Record 0fseek(StudentFil, 0 * sizeof(Student), SEEK_SET);

fwrite(&NewStudent,sizeof(Student),(long)1,StudentFil);

Replace Record 1fseek(StudentFil, 1 * sizeof(Student), SEEK_SET);

fwrite(&NewStudent,sizeof(Student),(long)1,StudentFil);

Replace Record 2fseek(StudentFil, 2 * sizeof(Student), SEEK_SET);

fwrite(&NewStudent,sizeof(Student),(long)1,StudentFil);

Append/Add New Record 3fseek(StudentFil, 3 * sizeof(Student), SEEK_SET);

fwrite(&NewStudent,sizeof(Student),(long)1,StudentFil);

38

Page 39: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Compile The Program!

Change

To

39

Page 40: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

40

Did It Do Anything? How Do You Know?

Yes It Did Something! The File Is 4 Bytes Bigger Than It Was.

Did It Do The Right Thing?

How Do You Know?

We Don’t’! How Could You Know?

Read The File?

Page 41: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

41

Page 42: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Create File – Open To Read Or Write

File Ptrs

42Execute This Program?

Open An Existing File To Read Or Write

Page 43: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

43

Page 44: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

44

fseek(FilePtr, NoBytes, SEEK_SET);SEEK_SET is a constant representing the beginning of the file. SEEK_END is a constant representing the end of the file.

fseek(StudentFil, 4 * sizeof(Student), SEEK_SET);

The size of each Student record is 36 Bytes.

Move the Read-Write Pointer 4 * 36 = 144 bytes from the beginning of the file referenced by the StudentFil ptr.

Can Do – Have Already Done!

About fseek

Page 45: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

45

Page 46: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

46

fread(&Info, InfoSize(byes), # records, fp);fread(&NewStudent,sizeof(Student),(long)1,StudentFil);

Read the 1 36-byte record of information, pointed to by the current Read-Write Pointer of the StudentFil, into the NewStudent container. Student Students[20]fread(&Students,sizeof(Student),(long)20,StudentFil);

Read twenty 36-byte records of information, pointed to by the current Read-Write Pointer of the StudentFil, into array Students.

FREAD can be used to write a single record or a block of records.

About fead

Page 47: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

47

Suppose the Input Buffer holds only two records.Student LocalYear;fseek(StudentFil, 2 * sizeof(Student), SEEK_SET);

fread(&LocalYear,sizeof(Student),(long)1,StudentFil);

Note that both Record 2 and Record 3 are in the Input Buffer. Ifthe program logic were to need to read either of these records, they would be retrieved from the buffer as opposed to readingthem from disk Much Faster [Nanosecond vs. Millisecond]

Page 48: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

48

Page 49: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Valid Reads For A File With 3 Records

Read Record 0fseek(StudentFil, 0 * sizeof(Student), SEEK_SET);

fread(&NewStudent,sizeof(Student),(long)1,StudentFil);

Read Record 1fseek(StudentFil, 1 * sizeof(Student), SEEK_SET);

fread(&NewStudent,sizeof(Student),(long)1,StudentFil);

Read Record 2fseek(StudentFil, 2 * sizeof(Student), SEEK_SET);

fread(&NewStudent,sizeof(Student),(long)1,StudentFil);

49

Page 50: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Compile The Program!

Change

To

50

Page 51: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Did It Do The Right Thing?

Absolutely!

But Will It Work For Multiple Records?

51

Page 52: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Compile The Program!

Change

52

Page 53: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

53

Wonder What The File Looks Like With A Text Editor?

Page 54: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

54

Binary Files Provide Some Additional Security InThat They Are Less Readable Than Text Files

Page 55: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Did It Do The Right Thing?

Absolutely!

But Does rb+ Really Allow

Reads & Writes?

55

Page 56: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Compile The Program!

Add This To The

Program

56

Page 57: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

57

Will This Really Work With Class Datatypes?

Page 58: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

58

Page 59: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Compile The Program!

Change

To

59

+

+

Page 60: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

60

Works For One Student

More Extensive Auto Testing!

Page 61: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

One 36-Byte Record

61

Page 62: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Compile The Program!

Change

To

62

Page 63: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

63

Page 64: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Eight 36-Byte Records

64

Page 65: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

65

Page 66: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Open An Existing Direct Access FileFILE

* AutoFil,

* StudentFil;

StudentFil = fopen("Student.Fil", "rb+");AutoFil = fopen("Auto.Fil", "rb+");

66

Page 67: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Open A New Direct Access File &Write A Record To Record 0 And A

Record To Record 1FILE

* StudentFil;

StudentNewStudent;

StudentFil = fopen("Student.Fil", "rb+");

if (NewStudent.Get())

fwrite(&NewStudent,sizeof(Student),(long)1,StudentFil);

if (NewStudent.Get())

fwrite(&NewStudent,sizeof(Student),(long)1,StudentFil);

fclose(StudentFil);

67

Page 68: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Open A Existing Access File Student.Fil (Has Two Records) & Add A Third

Record`

FILE

* StudentFil;

StudentNewStudent;

StudentFil = fopen("Student.Fil", "rb+");

fseek(StudentFil, 2 * sizeof(Student), SEEK_SET);

if (NewStudent.Get())

fwrite(&NewStudent,sizeof(Student),(long)1,StudentFil);

fclose(StudentFil);

Move To Record 2Third Record 0,1,2

68

Page 69: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Open A Existing Access File Student.Fil (Has Three Records) Display All 3 Records In Reverse Order

int

Counter;

FILE

* StudentFil;

StudentNewStudent;

StudentFil = fopen("Student.Fil", "rb+");

for (Counter = 2; Counter >= 0; Counter --)

{

fseek(StudentFil, Counter * sizeof(Student), SEEK_SET);

fread(&NewStudent,sizeof(Student),(long)1,StudentFil);

NewStudent.Display();

}

fclose(StudentFil);

Move To Record 2, 1, 0 Respectively

69

Page 70: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Student

NewStudent;

FILE

* StudentFil;

StudentFil = fopen("Student.Fil", "rb+");

if (NewStudent.Get() == VALID)

fwrite(&NewStudent,sizeof(Student),(long)3,StudentFil);

fclose(StudentFil);

Replace Record 3 [Fourth Record] With NewStudent

70

Page 71: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

71

Page 72: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Generic FileLength Function

72

long int Filelength (FILE * FilePtr, long int NoBytesPerRecord)

{

long int

Bytes;

fseek (FilePtr, 0L, SEEK_END);

Bytes = ftell (FilePtr);

return (Bytes / NoBytesPerRecord);

}

int

Counter;

FILE

* StudentFil;

NoRecords = FileLength(StudentFil, sizeof(Student));

Belongs in Utilities.cpp

Update It Now!

Test It Now!

Page 73: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

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

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

// //

// WriteRecord //

// //

// Purpose : Write the direct access record RecordNo from file *fp from //

// container Info. No error checking yet! //

// //

// Written By : Dr. Thomas E. Hicks Environment : Windows 2000 //

// Date : XX/XX/XX Compiler : Visual C++ //

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

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

template <class InfoType>

bool WriteRecord(InfoType *Info, long int RecordNo, FILE *fp)

{

fseek(fp, RecordNo * sizeof(InfoType), SEEK_SET);

fwrite(Info, (long)sizeof(InfoType), 1L, fp);

return (SUCCESSFUL);

}

Generic WriteRecord

73

Belongs in Utilities.hpp

Update It Now!

Page 74: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Student

NewStudent;

FILE

* StudentFil;

long int

Counter = 0;

StudentFil = fopen("Student.Fil", "wb+");

while (NewStudent.Get() == VALID)

fwrite(&NewStudent,sizeof(Student),Counter++,StudentFil);

fclose(StudentFil);

Test Generic WriteRecord

74

Test It Now!

Not A Great Solution – Does Not Trap ErrorsNever Returns UNSUCCESSFUL – See Chapter 11! 74

Page 75: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

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

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

// //

// ReadRecord //

// //

// Purpose : Read the direct access record RecordNo from file *fp into //

// container Info. No error checking yet! //

// //

// Written By : Dr. Thomas E. Hicks Environment : Windows 2000 //

// Date : XX/XX/XX Compiler : Visual C++ //

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

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

template <class InfoType>

bool ReadRecord(InfoType *Info, long int RecordNo, FILE *fp)

{

fseek(fp, RecordNo * sizeof(InfoType), SEEK_SET);

fread(Info, (long)sizeof(InfoType), 1L, fp);

return (SUCCESSFUL);

}

Generic ReadRecord

75

Belongs in Utilities.hpp

Update It Now!

Page 76: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Student

NewStudent;

FILE

* StudentFil;

long int

Counter,

NoRecords;

StudentFil = fopen("Student.Fil", "rb+");

NoRecords = FileLength(StudentFil, sizeof(Student));

for (Counter = NoRecords - 1; Counter >=0; Counter --)

if (ReadRecord(&NewStudent,Counter,StudentFil))

NewStudent.Display();

fclose(StudentFil);

Test Generic ReadRecordFile Exists From Test Of WriteRecord

76

Test It Now!

Not A Great Solution – Does Not Trap ErrorsNever Returns UNSUCCESSFUL – See Chapter 11! 76

Page 77: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Selection Of The RightData Structure

SOFTWARE ENGINEERING!

Page 78: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Almost Every Application Starts With Some Data You Need To Manage

Students

Integers

PartsParts

Page 79: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

class Part{public:

private:char Name [26];long int No, Quantity, DeptNo;double Cost;// . . .};

You Do A Systems Analysis & Determine What Data Is NeededYou Create Your Base Class

Page 80: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

class Part{public:

private:char Name [26];long int No, Quantity, DeptNo;double Cost;// . . .};

You Do A Systems Analysis & Determine What Data Is NeededYou Create Your Base Class

Page 81: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

class Part{public:

Part (char NewName[] = "", long int NewNo = 0, long int NewDeptNo = 0, long int NewQuantity = 0, double NewCost = 0.0);

~Part (void);void Set (char NewName[] = "", long int NewNo = 0, long int NewDeptNo = 0,

long int NewQuantity = 0, double NewCost = 0.0);bool Get(void);long int Key(void);long int No_(void);double Cost_(void);long int Quantity_(void);long int DeptNo_(void);

private:char

Name [26];long int

No, Quantity,DeptNo;

doubleCost;

};

Your System Analysis Will Help You Determine The Necessary Support Functions

Accessor & Mutator Functions

Page 82: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

class Part{public:

Part (char NewName[] = "", long int NewNo = 0, long int NewDeptNo = 0, long int NewQuantity = 0, double NewCost = 0.0);

~Part (void);void Set (char NewName[] = "", long int NewNo = 0, long int NewDeptNo = 0,

long int NewQuantity = 0, double NewCost = 0.0);bool Get(void);long int Key(void);long int No_(void);double Cost_(void);long int Quantity_(void);long int DeptNo_(void);

private:char

Name [26];long int

No, Quantity,DeptNo;

doubleCost;

};

Your System Analysis Will Help You Determine The Necessary Support Functions

Accessor & Mutator Functions

Page 83: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

friend ostream & operator << (ostream & OutputStream, Part P);

// I have decided that Name is to be the Primary Key for this record type. bool operator == (const Part & P);bool operator > (const Part & P);bool operator >= (const Part & P);bool operator < (const Part & P);bool operator <= (const Part & P);bool operator != (const Part & P);

void operator = (const Part & P);

// I have decided that Name is to be the Primary Character Key for this record type. bool operator == (const char Key[]);bool operator > (const char Key[]);bool operator >= (const char Key[]);bool operator < (const char Key[]);bool operator <= (const char Key[]);bool operator != (const char Key[]);void operator = (const char Key[]);

// I have decided that No is to be the Primary Integer Key for this record type. bool operator == (const long int Key);bool operator > (const long int Key);bool operator >= (const long int Key);bool operator < (const long int Key);bool operator <= (const long int Key);bool operator != (const long int Key);void operator = (const long int Key);

Your Specifications Will Almost Always Dictate Your Operator Overload DesignI always do overload ostream & operator << for diagnostic testing

If the specifications want reports that are in order by the Part.Name

I will have this collection

Required Only For Deep Copy

If the specifications want are going to search, or compare, the base class with a character

string, I will have this collection

If the specifications want are going to search, or compare, the base class with a long integer,

I will have this collection

There are ways to do generics with more than one char string or integer.

Page 84: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Specifications

Requirements

Page 85: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

The user will be able to search 1,000,000 records by Part.No and display the sought record in no more than .5 seconds.

The user will be able to add a new part to

999,999 others in no more that

1.0 seconds.

Most Systems Should Have Some Written Requirements

Page 86: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Out Requirements Almost Always Require The Following Functionality

SearchAdd

Delete

Page 87: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

1,000,000 Parts~20,000 Byte Records

1,000,000 x 20,000 =20,000,000,000 Bytes =

18.63 GB

Have To Use A File

Page 88: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Compute The Average Search Time

Divide The Time RequiredTo Search Each Record

By The Number Of Records

Page 89: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Create a direct access file with 1,000,000 Records – 20,000 Bytes Each – the content (x) does not matter.

To Calculate Average Search Time For A Computer - 1

1,000,000999,999999,998999,997

123

xxxx

xxx

Direct Access File

4 x

Page 90: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Maybe Write 1,000,000 Records – 20,000 Bytes Each. The data on the file (x) is unimportant.

Create an internal memory array whose integer data members are 1 1,000,000 randomly mixed.

To Calculate Average Search Time For A Computer - 2

1,000,000999,999999,998999,997

123

xxxx

xxx

Direct Access File

1,000,000999,999999,998999,997

123

2874

65341,124

32,4128

23,311

Internal Memory Array

4 x 4 2,301

Page 91: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Start the clock

To Calculate Average Search Time For A Computer - 3

1,000,000999,999999,998999,997

123

2874

65341,124

32,4128

23,311

A

4 2,301

For I = 1 To 1,000,000 ReadRecord(&P, A[I], fp)

Read record # 34,412Read Record # 8Read Record # 23,311Read Record # 2,301...Read Record # 34124Read Record # 65Read Record # 874Read Record # 2

Stop the clock

Compute The Total # Seconds

# SecondsAverage Search = # Records

Page 92: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Run The Program 10 Time &Get A Range Of Values?

Drive Speed (5200, 7600, etc.)Drive Type (Internal, External, IDE-Sata-USB-Firewire-ESata

Degree Of Optimization Optimized Fragmented

Other Programs Running

Page 93: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Basic Assumptions ForThis Set Of Slides

1,000,000 RecordsTime To Read/Write 1 Record

Is 1/200 Second

200 Records/Second

Page 94: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Design Consideration 1One Unordered

Direct Access File

Page 95: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per Second

Parts

D

A

FILE

1,000,000

1

Page 96: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Design Consideration 1One Unordered

Direct Access File

Search

Page 97: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Unordered Direct Access File

Parts – Worst Search

0X

Sec

Sequential Search1,000,000 Records1,000,000/200 = 5,000 Seconds 1

D

A

FILE

1,000,000

5,000

Page 98: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Unordered Direct Access File

Parts – Average Search

Sec

Sequential Search1,000,000/2 = 500,000 Records500,000/200 = 2,500 Seconds 1

D

A

FILE

1,000,000

2,5000

Page 99: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Design Consideration 1One Unordered

Direct Access File

Add

Page 100: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Unordered Direct Access File

Parts – Worst Add

Sec

1

D

A

FILE

999,999

Append 1 Record To End Of File1 Write1/200 = .005 Seconds

.005W

Page 101: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Unordered Direct Access File

Parts – Average Add

Sec

Append 1 Record To End Of File1 Write1/200 = .005 Seconds

1

D

A

FILE

999,999

.005W

Page 102: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Design Consideration 1One Unordered

Direct Access File

Delete

Page 103: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Unordered Direct Access File

Parts – Worst DeleteKnow Location

Sec

Read Record 1,000,000

1

D

A

FILE

1,000,000

XR

Page 104: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Unordered Direct Access File

Parts – Worst DeleteKnow Location

Sec

Read Record 1,000,000Write To Record 999,9972/200 = .01 Sec 1

D

A

FILE

1,000,000W

.01

Page 105: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Unordered Direct Access File

Parts – Worst DeleteDon’t Know Location

Sec

Worst Search = 5,000 Seconds

1

D

A

FILE

1,000,000

XR

R

Page 106: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

5,000.005

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Unordered Direct Access File

Parts – Worst DeleteDon’t Know Location

Sec

Worst Search = 5,000 SecondsWrite To Record 999,999= 1/200 = .005 Sec

1

D

A

FILE

1,000,000W

Page 107: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Unordered Direct Access File

Parts – Average DeleteKnow Location

Sec

Read Record 1,000,000

1

D

A

FILE

1,000,000

XR

Page 108: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Unordered Direct Access File

Parts – Average DeleteKnow Location

Sec

Read Record 1,000,000Write To Record 999,9972/200 = .01 Sec 1

D

A

FILE

1,000,000W

.01

Page 109: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Unordered Direct Access File

Parts – Average DeleteDon’t Know Location

Sec

Average Search = 2,500 Seconds

1

D

A

FILE

1,000,000

XR

R

Page 110: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

2,500.005

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Unordered Direct Access File

Parts – Average DeleteDon’t Know Location

Sec

Average Search = 2,500 SecondsWrite To Record 999,999= 1/200 = .005 Sec

1

D

A

FILE

1,000,000W

Page 111: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

The user will be able to search 1,000,000 records by Part.No and display the sought record in no more than .5 seconds.

The user will be able to add a new part to

999,999 others in no more that

1.0 seconds.

Can’t Satisfy These Requirements Specifictions With One UnOrdered Array

Sec5,000

Sec.005

Page 112: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Binary SearchReview

You Have Done WithArrays But Many Of You

Have Not With Files

Page 113: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

On Exam/Quiz, You May Calculate Log2 (N)

113

Page 114: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

1 12 23 44 85 166 327 648 1289 25610 1,02411 2,04812 4,096

13 8,19214 16,38415 32,76816 65,536

If There Are N Nodes At This Level Of A Complete Tree, There Are N-1 Nodes Above This Level

Ball Park = ~16 114

Page 115: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Computer A Search 1 RecordOrdered/Sorted Direct Access Files “Ordered List”

Record Quantity = 100,000 Avr Read/Write Time = 20,000 Byte Record = .01 Sec

Worst Case: Sorted Read ~Log2(100,000) Records

~16.6 sec

115

Page 116: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Computer A Search 1 RecordOrdered/Sorted Direct Access Files “Ordered List”

Record Quantity = 100,000Avr Read/Write Time = 20,000 Byte Record = .01 Sec

Average Case: Sorted Read ~Log2(100,000)-1 Records

~16.6 – 1 – 15.6 sec

??-1??

116

Page 117: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

To Compute Binary Exact?

Avr Search = Randomly Search Each Element Once

1

2 2

3 333

= 1

= 4

= 12

Total Searches = 17

Avr Search = 17/7 = 2.43

Log2(15)=____2.8

117

Page 118: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

To Compute Binary Exact?

Avr Search = Randomly Search Each Element Once

1

2 2

3 333

4 4 4 4 4 4 4 4

= 1

= 4

= 12

= 32

Total Searches = 49

Avr Search = 49/15 = 3.27

Log2(15)=____3.9

118

Page 119: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

To Compute Binary Exact?

Avr Search = Randomly Search Each Element Once

Total Searches = 129

Avr Search = 129/31 = 4.16

Log2(31)=____ = 1

= 4

= 12

= 32

= 80

4.9

119

Page 120: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

120Complete

Binary Treeor

Binary Search

Worst Search Log2(N) Reads

Ave Search Log2(N)-1 Reads

120

Page 121: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Design Thought

Ready For A Sorted Direct Access File

121

Page 122: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Direct Access Files - Will Be Times We Delete (21)

122

8

21

25

32

58

85

7

555

0 0

21

25

32

58

85

6

555

There Will Be Times When Not All Of The Records Are Used - Record 0 Provides A Great Place To Store The Actual Number Of Valid Records - We Will Have To Keep

This Number Accurate! I Will Not Include It In Many Of The Sketches!

Page 123: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Design Consideration 2

One Ordered Direct Access File

Page 124: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Design Consideration 2

One Ordered Direct Access File

Search

Page 125: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Search

SecD

A

FILE

R Binary Search- Bigger

Page 126: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

SecD

A

FILE

R

Binary Search- BiggerBinary Search- Smaller

Parts – Worst Search

Page 127: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

SecD

A

FILE

Binary Search - Smaller

RBinary Search- Bigger

Got It!

Parts – Worst Search

Page 128: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

SecD

A

FILE

Binary SearchLog2 (1,000,000) = 20 20/200 = .1 Seconds

R Binary Search- Bigger

.1

Parts – Worst Search

Page 129: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

SecD

A

FILE

Half The Data At The BottomBinary Search - 1Log2 (1,000,000) = 20 - 119/200 = .1 Seconds

R

.095

Parts – Average Search

Page 130: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Design Consideration 2

One Ordered Direct Access File

Add

Page 131: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Add

SecD

A

FILE

100 200 300 400 500 600

New 50

Page 132: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Add

SecD

A

FILE

100 200 300 400 500 600

New 50

R

Page 133: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Add

SecD

A

FILE

100 200 300 400 500

New 50

W 600

Page 134: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Add

SecD

A

FILE

100 200 300 400 500

New 50

600

R

Page 135: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Add

SecD

A

FILE

100 200 300 400

500

New 50

W

600

Page 136: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Add

SecD

A

FILE

100 200 300 400

500

New 50

600

R

Page 137: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Add

SecD

A

FILE

100 200 300

400 500

New 50

W

600

Page 138: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Add

SecD

A

FILE

100 200 300

400 500

New 50

600

R

Page 139: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Add

SecD

A

FILE

100 200

300 400 500

New 50

W

600

Page 140: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Add

SecNew 50

R

D

A

FILE

100 200

300 400 500 600

Page 141: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Add

SecNew 50

W

D

A

FILE

100

200 300 400 500 600

Page 142: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Add

SecNew 50

R

D

A

FILE

100

200 300 400 500 600

Page 143: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Add

SecNew 50

W

D

A

FILE

100 200 300 400 500 600

Page 144: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Add

SecD

A

FILE

100 200 300 400 500

New 50 W

600

Read 999,999 = 4,999.995 Seconds Write 999,999 = 4,999.995 SecondsWrite New = .005 Seconds

Page 145: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

10,000.000

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Add

Sec

New 50 100 200 300 400 500 600

Read 999,999 = 4,999.995 Seconds Write 999,999 = 4,999.995 SecondsWrite New = .005Update Record 0 = .005 = 10,000.000 Seconds

Page 146: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Average Add

SecD

A

FILE

100 200 300 400 500 600

New 350

Page 147: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Average Add

SecD

A

FILE

100 200 300 400 500 600

New 350

R

Page 148: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Average Add

SecD

A

FILE

100 200 300 400 500

New 350

W 600

Page 149: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Average Add

SecD

A

FILE

100 200 300 400 500

New 350

600

R

Page 150: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Average Add

SecD

A

FILE

100 200 300 400

500

New 350

W

600

Page 151: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Average Add

SecD

A

FILE

100 200 300 400

500

New 350

600

R

Page 152: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Average Add

SecD

A

FILE

100 200 300

400 500

New 350

W

600

Page 153: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Average Add

SecD

A

FILE

100 200 300

400 500

New 350 W

600

Read Half + 1 = 2,500.005 Seconds Write Half = 2,500 Seconds

Page 154: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

5,000.01

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Average Add

SecD

A

FILE

100 200 300

400 500

New 350

600

Read Half + 1 = 2,500.005 Seconds Write Half = 2,500 SecondsWrite New = .005Update Rec 0 = .005 = 5,000.015 Seconds

Page 155: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Design Consideration 2

One Ordered Direct Access File

Delete

Page 156: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Delete

Sec

To Delete 50

Worst BinarySearch To Find Location Log2 (1,000,000) = 20 20/200 = .1 Seconds 100

200 300 400 500 600

Location

Page 157: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Delete

Sec

To Delete 50

Worst Binary Search To Find Location Log2 (1,000,000) = 20 20/200 = .1 Seconds 100

200 300 400 500 600

R

Page 158: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Delete

SecWorst Binary Search To Find Location Log2 (1,000,000) = 20 20/200 = .1 Seconds

200 300 400 500 600

W 100

Page 159: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Delete

SecWorst Binary Search To Find Location Log2 (1,000,000) = 20 20/200 = .1 Seconds

200 300 400 500 600

100

R

Page 160: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Delete

SecWorst Binary Search To Find Location Log2 (1,000,000) = 20 20/200 = .1 Seconds 200

300 400 500 600

W

100

Page 161: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Delete

SecWorst Binary Search To Find Location Log2 (1,000,000) = 20 20/200 = .1 Seconds 200

300 400 500 600

100

R

Page 162: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Delete

SecWorst Binary Search To Find Location Log2 (1,000,000) = 20 20/200 = .1 Seconds 200

300

400 500 600

W

100

Page 163: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Delete

SecWorst Binary Search To Find Location Log2 (1,000,000) = 20 20/200 = .1 Seconds 200

300

400 500 600

100

R

Page 164: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Delete

SecWorst Binary Search To Find Location Log2 (1,000,000) = 20 20/200 = .1 Seconds 200

300 400

500 600

W

100

Page 165: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Delete

SecWorst Binary Search To Find Location Log2 (1,000,000) = 20 20/200 = .1 Seconds 200

300 400

500 600

100

R

Page 166: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Delete

SecWorst Binary Search To Find Location Log2 (1,000,000) = 20 20/200 = .1 Seconds 200

300 400 500

600W

100

Page 167: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Delete

SecWorst Binary Search To Find Location Log2 (1,000,000) = 20 20/200 = .1 Seconds 200

300 400 500

600

100

R

Page 168: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Delete

SecWorst Binary Search To Find Location Log2 (1,000,000) = 20 20/200 = .1 Seconds 200

300 400 500 600

W

100

Page 169: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Worst Delete

SecWorst Binary Search To Find Location Log2 (1,000,000) = 20 20/200 = .1 Seconds

Read 999,999 = 4,999.995 SecWrite 999,999 = 4,999.995 SecUpdate Rec 0 = .005 Sec

200 300 400 500 600

100

10,000.095

Page 170: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Average Delete

Sec

Average Binary Search To Find Location Log2 (1,000,000)-1 = 20 -1 = 1919/200 = .095 Seconds

100 200 300 400 500 600

Location

50

Page 171: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Average Delete

SecAverage Binary Search To Find Location Log2 (1,000,000)-1 = 20 -1 = 1919/200 = .095 Seconds 200

300

400 500 600

100

R

Page 172: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Average Delete

SecAverage Binary Search To Find Location Log2 (1,000,000)-1 = 20 -1 = 1919/200 = .095 Seconds 200

300 400

500 600

W

100

Page 173: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Average Delete

SecAverage Binary Search To Find Location Log2 (1,000,000)-1 = 20 -1 = 1919/200 = .095 Seconds 200

300 400

500 600

100

R

Page 174: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Average Delete

SecAverage Binary Search To Find Location Log2 (1,000,000)-1 = 20 -1 = 1919/200 = .095 Seconds 200

300 400 500

600W

100

Page 175: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Average Delete

SecAverage Binary Search To Find Location Log2 (1,000,000)-1 = 20 -1 = 1919/200 = .095 Seconds 200

300 400 500

600

100

R

Page 176: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Average Delete

SecAverage Binary Search To Find Location Log2 (1,000,000)-1 = 20 -1 = 1919/200 = .095 Seconds 200

300 400 500 600

W

100

Page 177: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Average Delete

SecAverage Binary Search To Find Location Log2 (1,000,000)-1 = 20 -1 = 1919/200 = .095 Seconds

Read 500,000 = 2,500 SecWrite 499,999 = 2,499.995 SecUpdate Rec 0 = .005 Sec

200 300 400 500 600

100

5,000.095

Page 178: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Design Consideration 2

One Ordered Direct Access File

To Get It Ordered We Often Need

To Sort

Page 179: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Sort – Order N2

Days1,000,000 x 1,000,000 = 1,000,000,000,0001,000,000,000,000/200 = 5,000,000,000 Sec 5,000,000,000/60 = 83,333,333 Minutes83,333,333/60 = ~1,388,889 Hours1,388,889/24 = ~57,870 Days

~5,000.090

1

D

A

FILE

1,000,000

Page 180: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Assume We Have 1,000,000 Data ItemsAssume That For Our Hardware & Data Item Size

We Can Read 200 Data Items Per SecondAssume Our Data Is In One Ordered Direct Access File

Parts – Sort – Order N Log2N

Days1,000,000 x 20 = 20,000,00020,000,000/200 = 100,000 Seconds100,000/60 = 1,667 Minutes1,667 /60 = ~27.78 Hours27.78/24 = ~1.16 Days

~1.16

1

D

A

FILE

1,000,000

Page 181: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

The user will be able to search 1,000,000 records by Part.No and display the sought record in no more than .5 seconds.

The user will be able to add a new part to

999,999 others in no more that

1.0 seconds.

Can’t Satisfy These Requirements Specifictions With One Ordered Array

Sec

Sec9,999.995

.1

Page 182: 1. 2 C/C++ Text File Functions  fopen  opens a text file.  fclose  closes a text file.  feof  detects end-of-file marker in a file.  fscanf

Need Better!

Come To Next Class!

182


Recommended