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
Carbon dioxide gas expands isotherm a turbine from 1 mpa, 500 k at 200 kpa. assuming the ideal gas model and neglecting the kinetic and potential energies, determine the change in entropy, heat transfer and work for each kilogram of co2.
Answers: 2
question
Engineering, 04.07.2019 18:10
Condition monitoring is a major component of. (clo4) a)- predictive maintenance. b)-preventive maintenance c)-proactive maintenance d)-reactive maintenance.
Answers: 1
question
Engineering, 04.07.2019 18:10
Items are similar to the free issue items, but their access is limited. (clo5) a)-bin stock items free issue b)-bin stock controlled issue c)-critical or insurance spares d)-rebuildable spares e)-consumables
Answers: 1
question
Engineering, 04.07.2019 19:10
Afoot bridge is made as a simple deck, 4 m long, with a cross section 2 m (wide) and 20 cm thick, and made of wood. the deck is supported at the two ends. the maximum load allowable on the bridge is 10 tons, provided it is uniformly distributed on the deck. to sense this load, a strain gauge is placed at the center of the bridge and its resistance is monitored. if the sensor has a nominal resistance of 350 s2 and a gauge factor of 3.6, what is the reading of the strain gauge at maximum load? the modulus of elasticity for the wood used in the construction is 10 gpa.
Answers: 2
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
Computers and Technology, 24.06.2019 11:30
question
Mathematics, 24.06.2019 11:30
question
Mathematics, 24.06.2019 11:30
Questions on the website: 13722367