Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-24-2003, 11:32 AM   #1
Registered: Jul 2003
Posts: 162

Rep: Reputation: Disabled
Lookup distances between cities in TX?

For my history homework, I have to lookup the distance between like 60 cities. And, me being lazy, would like to know how to do this in C/C++. I don't know much about sockets (because I used to use dev c, on windows). Is there any cgi-script that it could use and then format the data?
Old 08-24-2003, 12:13 PM   #2
Registered: Jul 2003
Posts: 162

Original Poster
Rep: Reputation: Disabled
Ok, I've found a website that will get the distance between two cities (seems like there's alot of cities)

But, since I don't know socket programming, could anyone help me?
Old 08-24-2003, 01:18 PM   #3
Senior Member
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Dude, you're trying to kill a fly with a sledgehammer. You don't need socket programming to look up distances between cities. By the time you've entered the names of each city in a text file, you could have the information already. Just go to, choose driving directions, then enter the city/state combinations.

To get the same result with socket programming you obviously have to set up the program, then you need to figure out the protocol (sounds like HTTP) to communicate with the server, and then parse the the data when it comes back.

If you proclaim to be "lazy" then I guarantee you writing a socket program is most definitely not the path of least resistance.

Just my
Old 08-24-2003, 01:20 PM   #4
Registered: Jul 2003
Posts: 162

Original Poster
Rep: Reputation: Disabled
I already have the text file will all the cities. I don't want to lookup 90 cities by hand.
Old 08-24-2003, 02:43 PM   #5
Senior Member
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
this is just a rough idea and might be a load of rubbish but anyway, when you goto one of these websites and type in the place names it must go to some html page like(this is made up)

you can see where it goes by looking at the html source and see what happens to the contents of the edit boxes. using perl or awk you could then take your file of places and produce a file containing the url's, you could then run that through wget and get the html pages with all the distances on. which you could then extract with grep.

Last edited by kev82; 08-24-2003 at 02:44 PM.
Old 08-24-2003, 02:44 PM   #6
Registered: Jul 2003
Posts: 162

Original Poster
Rep: Reputation: Disabled
I already know the url

I need help programming it. It could be in perl/shell/c/c++
Old 08-24-2003, 02:53 PM   #7
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 68
Why not run a loop to get:
lynx -dump "" | grep nautical
Old 08-25-2003, 09:34 AM   #8
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
import httplib

cities = ["Houston, TX", "Dallas, TX", ... (fill in the rest here)]
host = ""
page =  "/cgi-bin/dist?"

for city1 in cities:
    for city2 in cities:
        param1 = city1.replace(" ", "+")
        param2 = city2.replace(" ", "+")
        params = "place1=%s&place2=%s" % (param1, param2)
        conn = httplib.HTTPConnection(host)
        conn.request("GET", page + params)
        response = conn.getresponse()
        if response.status != 200:
            print "Failed lookup on %s and %s." % (city1, city2)
            data =
            # parse the HTML for your answer here
Tar dar.

(PS - this code was written in oh ... about 5 minutes, maybe less)

Last edited by Strike; 08-25-2003 at 09:36 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Firefox pauses when scrolling long distances Charred Slackware 5 07-15-2005 02:04 PM
Traceroute, Ping, Domain Name Server (DNS) Lookup, WHOIS, and DNS Records Lookup netoknet General 1 05-09-2005 03:43 AM
change the distances between desktop icons hraposo Debian 2 11-27-2004 11:19 AM
change the distances between the icons in desktop hraposo Slackware 3 11-03-2004 01:49 PM
Samba, a tale of two cities kcourser Linux - Networking 3 03-12-2003 01:21 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:50 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration