Question
Objectives: Design Data Records using Structures.- Implement techniques to write and read formatted records from sequential text files. Background: To process sequential text files in
Objectives:
Design Data Records using Structures.- Implement techniques to write and read formatted records from sequential text files.
Background:
To process sequential text files in C we use the stdio.h. Functions include:fopen("filename", MODE), where MODE could be one of Read, Write (create new file/erase existing file), and Append (add to existing file). ('r', 'w' and 'a' respectively)fclose() to close a file and release its handle.fscanf() and fprintf() to read and write to a file.
PART I:
Overview of Sequential FilesIn this lab you will continue using this structure and implement an interactive program capable of prompting the user and storing 3 employee records into a file called "employee.dat".The format of the file would look like this sample:
ID FIRSTNAME LASTNAME
10 John Doe
20 Mary Jane
30 Jim Smith
The skeleton code developed from this lab is placed here for convenience, use the 3 functions specified in this program to perform the input and saving the records to the file.
#include struct employee { char firstname[40]; char lastname[40]; int id; }; typedef struct employee Employee; /* Input the employee data interactively from the keyboard */ void InputEmployeeRecord(Employee *ptrEmp); /* Display the contents of a given Employee record*/ void PrintEmployeeRecord(const Employee e); /* Save the contents of the employee record list to the newly created text file specified by FileName */ void SaveEmployeeRecord(const Employee e[], const char *FileName); void main() { Employee e1; // TODO: modify to input and save an array of 3 employee records InputEmployeeRecord(&e1); PrintEmployeeRecord(e1); SaveEmployeeRecord(e1, "employee.dat"); } |
PART II:
Retrieve the File you createdWrite a different program called fixcap.c that reads the file "employee.dat" created in part I containing the 3 records created in part I into an array called EmployeeList (of type employee, size 3). Then, use the WordCap(char *) function to capitalize only the first letter of each of the first and last names of the 3 employee records. Then save the new records back to the "employee.dat" file, overwriting the old records. Note: after you run program "fixcap.c" you can use the command "cat employee.dat" to view the contents of the file and verify the results.The file now should look like this sample:
ID FIRSTNAME LASTNAME
10 John Doe
20 Mary Jane
30 Jim Smith
Document EVERY function (purpose/input/output), and EVERY declaration (Variables and Arrays), and every structure definition as shown in the examples.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started