Ask a question from expert

Ask now

Write a program that reads data about people from a file.

2 Pages429 Words373 Views
   

Added on  2019-09-16

Write a program that reads data about people from a file.

   Added on 2019-09-16

BookmarkShareRelated Documents
Write a program that reads data about people from a file. You aresupposed to create a quick data file for testing purposes yourself,which has the following structure:each line contains a record of data about exactly one personeach record has the person's name, followed by a space, followed by the person's ageUnlike in other assignments, there is no indication of how many records there will be in the file. Also, we don't want to assume that you do a first scan to find out. Instead, I ask you to solve the problem of creating enough space for all the records by incrementally reading one record at a time, put it into a struct personand link that structure to the list of person structures that is already there. This means that your person structure needs to contain a pointer to the next structure in the list. This also means that you need to keep track of the structure that is the head of the list, as well as the structure that is at the end of the list by maintaining corresponding pointers.Here is a critical piece of code. It reads a record from the file, creates the space (i.e. structure) to hold the data and updates the pointers involved:while (2 == fscanf(people_data,"%s %d", person_current->name, &person_current->age)) { person_current->next = NULL; // provide space for the new last person person_last->next = (structperson *) malloc(sizeof(structperson)); // set the new last person person_last = person_last->next; // copy the current's person data just readinto the new last person *person_last = *person_current; // update age total and number of records age_total += person_current->age;
Write a program that reads data about people from a file._1

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Implementing Linked List in C++: Efficient Data Structure for Storing and Manipulating Elements
|3
|282
|146

Justification of other data structures and design issues.
|2
|453
|568

Computer Science Assignment Program Function
|2
|774
|691

Python Programming: Research Report
|7
|2904
|737

Postfix Calculator Assignment 2022
|8
|905
|19

Data Structures and Algorithms: Linked List Implementation for Student Records
|2
|862
|210