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, 04.07.2019 19:10
In general, how do thermosetting plastics compare to thermoplastics in mechanical and physical properties?
Answers: 3
question
Engineering, 04.07.2019 19:10
Estimate the change in specific internal energy au and specific enthalpy h from inlet to outlet for ethylene glycol (a liquid) flowing through each of the following devices: (a) a heat exchanger where the glycol temperature increases from 20 °c to 80 °c; (b) a pump operating at about 25 °c and increasing the glycol pressure from 100 kpa to 8 mpa.
Answers: 2
question
Engineering, 04.07.2019 19:10
Analyze the factors that influence the choice between the following pairs of processes to make the products indicated: i) sand casting versus die casting of an electric-motor housing ii) thread rolling versus machining of a bolt for high-strength application. (co3/c5)
Answers: 3
question
Engineering, 04.07.2019 19:20
The power source in a certain welding setup generates 3500w that is transferred to the low carbon steel work with a heat transfer factor of 0.85. the melting factor in the operation is 0.45. a continuous fillet weld is to be made with a cross-sectional area of 23 mm2 determine the travel speed at which the welding can be accomplished.
Answers: 3
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
Business, 05.02.2021 02:00
question
Mathematics, 05.02.2021 02:00
question
Mathematics, 05.02.2021 02:00
question
Mathematics, 05.02.2021 02:00
Questions on the website: 13722359