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
Thermal stresses are developed in a metal when its a) initial temperature is changed b) final temperature is changed c) density is changed d) thermal deformation is prevented e) expansion is prevented f) contraction is prevented
Answers: 2
question
Engineering, 04.07.2019 18:20
Wiy doeres rere okhn a pump whon working betwon the same pressure range?
Answers: 2
question
Engineering, 04.07.2019 19:10
An external consultant recommends that a plant installs a bank of capacitors for power factor correction. this will reduce the peak electrical demand charges by an average of 93 kw every month. the plant current pays $13 per kw in peak demand charges. the capacitor bank will include 223 kw of fixed capacitors, and 183 of variable capacitors. the fixed capacitors cost $59 per kw, and the variable capacitors will cost $65 per kw. the consultant charges 21% of the equipment costs to install the capacitors. because this project will reduce the demand for the electric utility, they are prepared to provide a one-time rebate of $42 per kw of reduced demand. what is the simple payback period for this project (in years)?
Answers: 2
question
Engineering, 06.07.2019 02:30
A12 mm diameter shaft runs in a plain cylindrical bush 30 mm long that is located in an 18 mm diameter hole in a housing. the shaft-inner bush fit is h8 f and the outer bush-housing fit is h7-p6. make a fully cimensioned sketch of the bush with tolerances. find the maximum and minimum clearance or interference for both fits on the inner and outer diameters of the bush
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
Mathematics, 27.11.2020 04:40
question
Mathematics, 27.11.2020 04:40
question
Social Studies, 27.11.2020 04:40
question
Mathematics, 27.11.2020 04:40
Questions on the website: 13722363