chapter 10.6.4 structures & arrays
this is a question at the end the chapter:
[4] a selection of towns/cities in three conties in england have populations to the nearest 100 as shown
county.................town/city.............population
-----------------------------------------------------------
wiltshire.................salisbury.............37 000
............................swindon............170 000
............................marlborough..........7 000
oxfordshire..............oxford..............11500 0
............................banbury..............3 8700
............................witney................ 17500
dorset....................poole................137 000
............................dorchester...........1 4500
............................weymouth...........494 00
(ps..forget the dots, just there to align the columns, spaces wouldnt work)
initialise the following the arrays.
(a) A one dimensional array containing the names of the counties.
(b) A two dimensional array containing records of the names of the towns/ cities and their respective populations, where each row represents a different county, in the order given in the first array.
Using the arrays from (a) and (b) write procedures to input the name of a county and the name of a town/ city, and perform a serial search on the one dimensional array to match the county and obtain a row subscript, then perform a serial search on the two dimensional array, to match the town/ city, and obtain a column subscript. Using the row and column subscripts, access the two dimensional array and display the value for the population of the chosen town/ city.
-----------------------------------------------------------------------------------
i have been trying various ways to attack this problem with my limited knowledge of 'c', however i cant get a mental picture of the array structure as listed above.
1) how does one link array (a) with array(b) ?
2) how does the row subscript on array (a) effect the column (or row) subscript on array (b) ?
i know what a two dimensional arra looks like and how to initialise one, this is my code so far
#include <stdio.h>
/* one dimensional array containing the names of the counties
0 9 20 */
char counties[28] = "WiltshireOxfordshireDorset";
/* two dimensional array containing records of the names of the
towns/cities and their respective populations */
char towns_cities[3][48] = {{"salisbury 37000 swindon 170000 marlborough 7000"},
{"oxford 115000 banbury 38600 witney 17500"},
{"poole 137000 dorchester 14500 weymouth 49400"}};
void main(void)
{
}
i dont want the answer, just a step in the right direction please
i re-iterate please
ive been on this problem a few days now
thanks in advance
luigi