Question: DELETE THE 4-- D STRUCTS WITHOUT MAKING ANY MEMORY LEAK ! void get_state_data(state * st, ifstream & input,int states ){ string line; int i =
DELETE THE 4-- D STRUCTS WITHOUT MAKING ANY MEMORY LEAK !
void get_state_data(state * st, ifstream & input,int states ){ string line; int i = 0, pos_char=0; while(i < states){ pos_char = input.tellg(); getline(input,line); int space = 0; for (int j = 0; j < line.length(); j++) { char character = line[j]; if (character == ' ') space++; } if (space==2){ input.seekg(pos_char); //cout<<"pos_char "< void get_county_data(int i, state * st, ifstream &input, county * c, int county_size, int &pos_char) { string line; int j = 0; while ( j < county_size){ pos_char = input.tellg(); getline(input,line);getline(input,line); int space =0; for (int g = 0; g < line.length(); g++) { char charac = line[g]; if (charac == ' ') space++; } if (space>2) { input.seekg(pos_char); input>>st[i].c[j].name>> st[i].c[j].population>> st[i].c[j].avg_income>> st[i].c[j].avg_house>> st[i].c[j].cities; cout<< st[i].c[j].name<<" " << st[i].c[j].population << " "< state* create_states(int states){ state * st = new state [states]; return st; } county* create_counties(state* s, int i){ county * c = new county [s[i].counties]; return c; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
