Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Read in and parse the input file (using c programing languge) The input file is in world_cities.txt. Download this file, and drag it into your

Read in and parse the input file

(using c programing languge)

The input file is in world_cities.txt. Download this file, and drag it into your Eclipse project. This file has 47913 lines. Each line has information about a world city, specifically the six attributes youll need to use in this lab, but of course represented textually. These attributes are separated by commas without surrounding spaces. We call such a file a CSV file. (CSV is short for comma-separated values.) Heres the line of the world_cities.txt file for Albany:

us,Albany,NY,93794,42.6525000,-73.7566667

Here, the country code is us, the city name is Albany, the region is NY, the population is 93794, the latitude is 42.6525000, and the longitude is -73.7566667. You already know how to read in a file, line by line. But if you forgot, see the notes from notes. But how can you process this line? We have already seen that you can separate a line of string into words by using strtok, if you forgot, you can go back and review its usage from our previous lecture notes.

However, one extra step you need to do here is to convert some of the information you read to numbers, such as population, coordinates, etc. So, what do you need to do? You can use atof to convert a string to a double, or use function to convert a string to an integer. You will of course need to have the correct data in the string format, such as "12.45" can be converted using atof to double, but cannot be converted to integer using atoi.

Now, after you have parsed all the data into the correct data type, you need to store them somewhere.

To organize these data, you need to define a City struct, and create an array of City struct, and store all the information. I would recommend you to test to read in maybe 10 to 20 lines, see if you can successfully parse the data, store them in the City struct array, and access them.

Write the output file

Once you have the list of references to City struct, you can test by writing all information to an output file. This file contains only the information you care compared to the original input. This is not required, but I recommend you to do this to make sure you have got all things correct so far.

Andorra La Vella,20430,42.5,1.5166667 Canillo,3292,42.5666667,1.6 Encamp,11224,42.5333333,1.5833333 La Massana,7211,42.55,1.5166667 Les Escaldes,15854,42.5,1.5333333 ... Redcliffe,38231,-19.0333333,29.7833333 Rusape,23761,-18.5333333,32.1166667 Shurugwi,17107,-19.6666667,30.0 Victoria Falls,36702,-17.9333333,25.8333333 Zvishavane,79876,-20.3333333,30.0333333

I put some of worldcities.txt below Worldcities.txt ad,Andorra La Vella,07,20430,42.5,1.5166667 ad,Canillo,02,3292,42.5666667,1.6 ad,Encamp,03,11224,42.5333333,1.5833333 ad,La Massana,04,7211,42.55,1.5166667 ad,Les Escaldes,08,15854,42.5,1.5333333 ad,Ordino,05,2553,42.55,1.5333333 ad,Sant Julia De Loria,06,8020,42.4666667,1.5 ae,Abu Dhabi,01,603687,24.4666667,54.3666667 ae,Dubai,03,1137376,25.2522222,55.28 ae,Sharjah,06,543942,25.3622222,55.3911111 af,Acin,18,15098,34.081667,70.668333 af,Anar Darreh,06,10023,32.762222,61.6525 af,Andarab,03,27034,35.634444,69.259444 af,Asadabad,34,48400,34.8725,71.146111 af,Asmar,34,15708,35.033056,71.357778 af,Aybak,32,47877,36.265278,68.016667 af,Azrow,36,12526,34.173333,69.645278 af,Baglan,03,108481,36.126944,68.705278 af,Bagrami,13,30256,34.494167,69.274722 af,Baraki Barak,17,22305,33.9675,68.948611 af,Cah Ab,26,23424,37.399444,69.815278 af,Carikar,22,53693,35.013611,69.171389 af,Ciras,33,12778,35.416667,65.983333 af,Dawlatabad,07,13603,36.437222,64.922778 af,Dawlatabad,30,17674,36.988333,66.8225 af,Deh Rawud,39,25683,32.621944,65.460278 af,Eskasem,01,12120,36.709167,71.573889

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions

Question

9-18. What reader benefits are included?

Answered: 1 week ago

Question

9-19. What tools does the writer use to reinforce his position?

Answered: 1 week ago