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 18:10
For the closed feedwater heater below, feedwater enters state 3 at a pressure of 2000 psia and temperature of 420 °f at a rate of ix10 ibhr. the feedwat extracted steam enters state 1 at a pressure of 1000 psia and enthalpy of 1500 btu/lbm. the extracted er leaves at an enthalpy of 528.7 btu/lbm steam leaves as a saturated liquid. (16) a) determine the mass flow rate of the extraction steam used to heat the feedwater (10) b) determine the terminal temperature difference of the closed feedwater heater
Answers: 3
question
Engineering, 04.07.2019 18:10
Slip occurs via two partial dislocations because of (a) the shorter path of the partial dislocation lines; (b) the lower energy state through partial dislocations; (c) the charge balance.
Answers: 1
question
Engineering, 04.07.2019 18:10
Machinery that is a key part of the process and without which the plant or process cannot function is classifed as: (clo4) a)-critical machinery b)-essential machinery c)-general purpose machinery d)-none of the specified options.
Answers: 1
question
Engineering, 04.07.2019 18:10
Aturning operation is performed with following conditions: rake angle of 12°, a feed of 0.35 mm/rev, and a depth of cut of 1.1 mm. the work piece is aluminum alloy 6061 with t6 heat treatment (a16061-t6). the resultant chip thickness was measured to be 1.0 mm. estimate the cutting force, fc. use shear stress of 207 mpa and coefficient of friction on the tool face of 0.6.
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, 16.12.2020 01:10
question
Mathematics, 16.12.2020 01:10
question
Mathematics, 16.12.2020 01:10
question
Mathematics, 16.12.2020 01:10