Question: I have these C code i want to add some function to it, I am confuse what to do with it. I run it in

I have these C code i want to add some function to it, I am confuse what to do with it. I run it in GNU 90

#include

#include

struct address_tag {

int houseNum;

char street[30];

char city[30];

char state[3];

};

typedef struct address_tag Address;

struct person_tag {

char firstName[20];

char lastName[20];

Address addr;

};

typedef struct person_tag Person;

void printAddress(Address addr);

void printPerson(Person per);

void displayPeople(Person ppl[], int pplCount);

void addPerson(Person newPerson, Person ppl[], int *pplCount);

void moveToTacoma(Person *per);

void moveAllToTacoma(Person ppl[], int pplCount);

int main(void) {

Person people[10] = {

{ "Joseph", "Miller", { 10, "Downing", "London",

"WA" } },

{ "Anne", "Simpson", { 1600, "Pennsylvania Ave",

"Columbia", "WA" } },

{ "Peter", "Price", { 832, "Main St.", "Dallas",

"TX" } }

};

int peopleCount = 3;

displayPeople(people, peopleCount);

Person historicFigure = { "Thea", "Foss", { 17, "Prospect St.",

"Tacoma", "WA" } };

addPerson(historicFigure, people, &peopleCount);

displayPeople(people, peopleCount);

moveAllToTacoma(people, peopleCount);

printf("After massive relocation "); // Now this works!

displayPeople(people, peopleCount);

return 0;

}

void printAddress(Address addr) {

printf("%d %s ",addr.houseNum, addr.street);

printf("%s, %s ",addr.city, addr.state);

}

void printPerson(Person per){

printf("%s, %s ",per.lastName, per.firstName);

printAddress(per.addr);

}

void displayPeople(Person ppl[], int pplCount) {

int i;

for (i = 0; i

printPerson(ppl[i]);

printf(" ");

}

}

void addPerson(Person newPerson, Person ppl[], int *pplCount) {

ppl[*pplCount] = newPerson;

(*pplCount)++;

}

void moveToTacoma(Person *per) {

strcpy(per->addr.city, "Tacoma");

strcpy(per->addr.state, "WA");

}

void moveAllToTacoma(Person ppl[], int pplCount) {

int i = 0;

for (i = 0; i

moveToTacoma(&ppl[i]);

}

}

these are the function i want to add

I have these C code i want to add some function to

2. Add function writeBinPeople1. The function takes the Person array and its count, then opens a file binout1.dat for writing in binary and writes each structure, one by one to it using function fwrite (do not write an entire array at once for this exercise). Call the function at the end of main. Compile and run to verify everything is done properly. You may open the file after writing it, using strings -n 2 binout1.dat command 3. To practice reading, write readBinPeople1 function that you are to call after writeBinPeople1 in main. The function takes no arguments, creates Person array and reads from binout1.dat using fread, one structure at a time, and then calls displayPeople function to see the contents in a formatted text view Make sure you comment out any other displayPeople calls in the code. Pretend you do not know the number of records ahead of time and use feof function while reading. Compile and run to verify everything is done properly. 4. You need to add one more function changeRecord that you are to call in between writeBinPeople1 and readBinPeople1. The function takes the record number to modify, e.g. value 2 signifies that person 3 in binout1.dat needs to be modified (Peter Price), as record counting starts at a zero. The function should consist of the following 5 statements: Open binout1.dat in a binary mode, for both reading and writing Create a Person variable and hardcode some data into that Person Use fseek to find record number 2 (3rd record overall lookup function fseek online or in your . book Use fwrite to overwrite that record with the Person variable you just created .Close the file 2. Add function writeBinPeople1. The function takes the Person array and its count, then opens a file binout1.dat for writing in binary and writes each structure, one by one to it using function fwrite (do not write an entire array at once for this exercise). Call the function at the end of main. Compile and run to verify everything is done properly. You may open the file after writing it, using strings -n 2 binout1.dat command 3. To practice reading, write readBinPeople1 function that you are to call after writeBinPeople1 in main. The function takes no arguments, creates Person array and reads from binout1.dat using fread, one structure at a time, and then calls displayPeople function to see the contents in a formatted text view Make sure you comment out any other displayPeople calls in the code. Pretend you do not know the number of records ahead of time and use feof function while reading. Compile and run to verify everything is done properly. 4. You need to add one more function changeRecord that you are to call in between writeBinPeople1 and readBinPeople1. The function takes the record number to modify, e.g. value 2 signifies that person 3 in binout1.dat needs to be modified (Peter Price), as record counting starts at a zero. The function should consist of the following 5 statements: Open binout1.dat in a binary mode, for both reading and writing Create a Person variable and hardcode some data into that Person Use fseek to find record number 2 (3rd record overall lookup function fseek online or in your . book Use fwrite to overwrite that record with the Person variable you just created .Close the file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!