Welcome to the CSIG, a Special Interest Group of the ACGNJ. The subject for this month is a simple text processing program. It uses the latest C++ compiler in Microsoft's Visual Studio 2005 so there are many new things to learn. The program may also be compiled using the free C++ Express compiler.
Here's the background: The Netgear router that I have in my house provides the option of sending a Security Log to my email address. When the email is received by my Eudora software it drops into a mail file determined by a simple filter. The mail file happens to be a simple text file. The data file is about 250,000 lines long and consists of a list of URL's that have been sent messages from my computer over the past year. Here's an example line,
[ALLOW:srx.main.ebayrtm.com] Source: 192.168.0.2 Friday, 22 Sep 2006 23:13:40
It's ridiculous to try to decipher this file because of the huge number of entries. The program reads the text file and creates a list of unique URL's that have been contacted. It also counts the number of times that each URL has been hit. It then presents a display sorted by either URL or count.
The program demonstrates reading text files, parsing lines of data, and creating a listing. It also allows copying the listing to the clipboard for saving or printing.
This is an exciting time for the C Language programming since Microsoft now has 4 different language compilers: C++, C++ Express, C-Sharp, and C-Sharp Express. These are all capable of creating Windows (tm) programs and the "Express" versions are free ! Additionally, Borland has just announced that it also has four new programs that are also available in free versions. These are Turbo C++, Turbo C-Sharp, Turbo Delphi and Turbo Delpi for .NET. You may also want to check with Intel and others for their generally free evaluation versions. Here a link with many compilers: http://www.willus.com/ccomp.shtml
MICROSOFT |
BORLAND |
INTEL |
BLOODSHED |
GCC, the GNU Compiler Collection - GNU Project |
Digital Mars C, C++ and D Compilers |
Others |
The beginning of the evening (starting at 7:30pm) will be a RANDOM ACCESS discussion. The main presentation will discuss the program.
Our download site has code and programs from most of our meetings. ( Source Code Files )
Sample Code =========== void Process(void) { Cursor->Current = Cursors::WaitCursor; Hashtable ^mUrl = gcnew Hashtable(10007); // Prime number benifit??? int lines = 0, hits = 0; try { StreamReader^ sr = gcnew StreamReader( LOGFILE ); // Read file String ^ hDelims = ":[]"; array^delimiter = hDelims->ToCharArray(); array ^ hTokens = nullptr; try { String^ slineBuff; int n, count; while ( slineBuff = sr->ReadLine() ) // Read 179829 lines. { ++lines; hTokens = slineBuff->Split(delimiter,5); n = hTokens->Length; if (n>2 && hTokens[1] == "ALLOW") { ++hits; if (mUrl->Contains(hTokens[2])) // www.google.com { count = (int)mUrl[hTokens[2]]; mUrl[hTokens[2]] = 1 + count; } else mUrl->Add(hTokens[2], 1); } } } finally { if ( sr ) { sr->Close(); delete (IDisposable^)sr; } } } catch ( Exception^ e ) { Console::WriteLine( "The file could not be read:" ); Console::WriteLine( e->Message ); }