100 likes | 115 Views
Learn about data hierarchy, file and stream concepts, and how to create, read, write, and update files in C. Understand sequential vs. random access files with hands-on lab assignments. Practice managing hardware inventory.
E N D
Lab guide # 10 C File Processing Review & Lab assignments
Key points • Data hierarchy • File & Stream • Create, read, write and update: • Sequential access file • Random access file
Bit, bytes, characters, records, files database Data hierarchy
File: • 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 File & Stream
Create 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+ Create, read, write and update
Fig. 11.8 Fig 11.12 Fig 11.15 Lab Assignment
Hardware Store You are the owner of a hardware store and need to keep an inventory. 4. Lab Assignmentstion 11 Tool Record • The tool identification number should be the record number.
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. Program