GIDForums  

Go Back   GIDForums > Computer Programming Forums > .NET Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Aug-2005, 18:46
pglibra pglibra is offline
New Member
 
Join Date: Jul 2005
Posts: 6
pglibra is on a distinguished road

Reading sequential files


Hello,
I'm trying to write a program that will accept a city and a zip code and write it to a file (city.txt).
Then be able to do a search by zip code to find the city.
Here is my function for the search routine.
I'm leaving something out but not sure what. After entering in data, then trying to do a search, no matter what zip I enter, it displays last city entered.
What do I use to locate a city by the zip entered? Substring?
Thanks alot.

C-SHARP / C# Code:
void searchCity()
{
	//declare variables
	String *zip = "";
	String *city ="";
	bool fileProblem = false;
	//declare CityZip object
	CityZip *cityObj = new CityZip;
	//declare StreamReader variable and open the file
	IO::StreamReader *inFile;
	try
	{
		inFile = IO::File::OpenText("city.txt");
	}
	catch (IO::IOException *ex)
	{
		fileProblem = true;
		Console::WriteLine(ex->Message);
	}

	if (fileProblem == false)
	{
		//read record
		Console::Write("Enter the zip: ");
		zip = Console::ReadLine();
		while (inFile->Peek() != -1)
		{
			cityObj->ReadRecordFromFile(inFile);
			zip = cityObj->GetCity();
		}	//end while

		//display result
		city =Convert::ToString(city->IndexOf(zip));
		Console::WriteLine("City: {0}", zip);

		//close the file
		inFile->Close();
	}	//end if
}	//end of searchCity function
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading Text Files DesperateCry C Programming Language 3 05-Apr-2005 14:55
Need help reading data from files blitzy C Programming Language 5 15-Mar-2005 19:07
Checking source codes of image, audio and video files onauc C Programming Language 5 26-Feb-2005 21:47
Reading and writing binary files in certain format Dream86 C++ Forum 10 06-Aug-2004 10:38
Can't view pages from another machine on the Intranet aevans Apache Web Server Forum 9 14-May-2004 02:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:50.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.