subject
Engineering, 18.12.2019 01:31 sanchezr7187

How to write the function state_totalpop(state* headstate), which takes in a pointer to the head element of a linked list and returns the total population sum for all elements in the list.

current code:
#include
#include
#include
typedef struct state_struct {
char code[3]; //two letter code of this state
int pop; //population of this state
struct state_struct* next; //pointer to next state
} state;
//state constructor
void state_create(state* thisstate, char thiscode[3], int thispop, state* nextstate) {
strcpy(thisstate-> code, thiscode);
thisstate-> pop = thispop;
thisstate-> next = nextstate;
}
void state_add(state* headstate, char addcode[], int addpop){
state* newstate = (state*)malloc(sizeof(state));
state_create(newstate, addcode, addpop, null);
state* currstate = headstate;
while (currstate-> next ! = null){
currstate = currstate-> next;
}
currstate-> next = newstate;
}
//returns total population for all states in list beginnging with *headstate
int state_totalpop(state* headstate){
int total = 0;
char stcode[3];
int statepop=0;
state* poplist = null;
poplist = (state*)malloc(sizeof(state));
state_create(poplist, stcode, statepop, null);
file* myfile = null;
myfile = fopen("uspops. txt", "r");
while (! feof(myfile)) {
fscanf(myfile, "%s", stcode);
fscanf(myfile, "%d", & statepop);
}
}
fclose(myfile);
return total;
}

ansver
Answers: 2

Another question on Engineering

question
Engineering, 03.07.2019 14:10
The y form of iron is known as: a) ferrite b) cementite c) perlite d) austenite
Answers: 3
question
Engineering, 04.07.2019 18:10
Abrake has a normal braking torque of 2.8 kip in and heat-dissipating cast-iron surfaces whose mass is 40 lbm. suppose a load is brought to rest in 8.0 s from an initial angular speed of 1600 rev/min using the normal braking torque; estimate the temperature rise of the heat dissipating surfaces.
Answers: 3
question
Engineering, 04.07.2019 18:10
Fluids at rest possess no flow energy. a)- true b)- false
Answers: 3
question
Engineering, 04.07.2019 18:10
Which of the following refers to refers to how well the control system responds to sudden changes in the system. a)-transient regulation b)- distributed regulation c)-constant regulation d)-steady-state regulation
Answers: 1
You know the right answer?
How to write the function state_totalpop(state* headstate), which takes in a pointer to the head ele...
Questions
question
Mathematics, 02.09.2019 11:10
question
Mathematics, 02.09.2019 11:10
question
Mathematics, 02.09.2019 11:10
question
Mathematics, 02.09.2019 11:10
question
History, 02.09.2019 11:10
Questions on the website: 13722360