WordCount Sample

Sample Overview

This sample offers an introduction to the base class library. It shows how to create an application that opens multiple files (specified on the command line) and counts each file's bytes, characters, words, and lines. The results from each file and the total of all files are sent to the console.

The following classes are used by the sample:

Usage

clix wordcount [-a] [-o] [-f<output-pathname>] [-c<codepage>] filename

The following table shows the command-line options used by the sample.

Option Description
-? Shows usage information.
-a Sorts word usage alphabetically.
-c Specifies the codepage to use to read the file.
-f:outfile Sends output to outfile instead of the console.
-o Sorts word usage by occurrence and then alphabetically.

Sample Source and Build Output Locations

The sample source is found in rotor\samples\utilities\wordcount.

The source file is:

The build output location is %TARGETCOMPLUS%\samples\utilities\wordcount.  The output file is an executable assembly named wordcount.exe.

Building the Sample

All samples are built from the buildall script. 

You can also build all the samples by switching to the root of the sample directory, sscli\samples, and typing build -c.

You can build this specific sample by switching to the sample directory and typing build -c.

Running the Sample

These steps require that the Shared Source CLI (SSCLI) be already built and functional.

  1. Run env.bat or source the env.csh or env.sh script files, depending on your platform.
  2. Switch to the %TARGETCOMPLUS%\samples\\utilities\wordcount directory.
  3. Type the following command:

    clix wordcount.exe filename

where filename is the name of the file in which to count words and lines.


Copyright (c) 2002 Microsoft Corporation. All rights reserved.