Presentation is loading. Please wait.

Presentation is loading. Please wait.

Review & Lab assignments

Similar presentations


Presentation on theme: "Review & Lab assignments"— Presentation transcript:

1 Review & Lab assignments
Lab guide # 10 C File Processing Review & Lab assignments

2 Key points Data hierarchy File & Stream
Create, read, write and update: Sequential access file Random access file

3 Data hierarchy Bit, bytes, characters, records, files database

4 File & Stream File: Stream: Read/Write function
A sequence of bytes, ends with end-of-file marker Structure File descriptor File control block Stream: Provide communication channel between files and programs File pointer: to be returned when open a file stdin, stdout, stderr Read/Write function fgets, fputc, fgets, fputs, fscanf, fprintf

5 Create, read, write and update
FILE *cfPtr; cfPtr = fopen(“clients.dat", “w”); Opening modes Character mode: r,w,a,r+,w+,a+, Binary mode: rb,wb,ab,rb+,wb+,ab+ Functions Random Sequential Read fread fscanf Write fwrite fprintf Pointer position fseek rewind Others feof, fclose

6 Sequential vs. Random access file
Properties Random Sequential Length of records Fixed Dynamic Access individual records without searching through other records Yes No, should be searched through other records Instant access to records No Data can be inserted without destroying other data No, Other data can be destroyed Data previously stored can be updated or deleted without overwriting Storage memory High Low Human readable

7 Lab Assignment Fig. 11.8 Fig 11.12 Fig 11.15

8 4. Lab Assignmentstion 11 Hardware Store You are the owner of a hardware store and need to keep an inventory. Tool Record Record # Tool name Quantity Cost The tool identification number should be the record number.

9 Program Initialize the random-access file “hardware.dat” to 100 empty records. (ONLY if it was empty) Menu Input a tool data. List all tools. Delete a tool record. Update a tool record.

10 Use this information to start your file.
Record number Tool name Quantity Cost 3 Sander 18 35.99 19 Hammer 128 10.00 26 Jigsaw 16 14.25 36 Mower 10 79.50 56 Saw 8 89.99 76 Screwdriver 236 4.99 81 Sledgehammer 32 19.75 88 Wrench 65 6.48


Download ppt "Review & Lab assignments"

Similar presentations


Ads by Google