|
|
|
|
|
|
|
//******************************************************************
// CharCount program
// This program counts the frequency of occurrence of certain
// characters in a text file. The specific characters to be
// counted are read from the standard input device
//******************************************************************
#include <iostream.h>
#include <iomanip.h> // For setw()
#include <fstream.h> // For file I/O
#include "bool.h" // For Boolean type
const int MAX_LENGTH = 256; // Max. number of different
// characters
const char SENTINEL_CHAR = '#'; // Marks the end of the character
// list
void GetCharList( char[], int& );
void Print( const int[], const char[], int );
void ScanList( const char[], int, char, int&, Boolean& );
void ZeroFreqList( int[], int );
int main()
{
char charList[MAX_LENGTH]; // Chars to be counted
int freqList[MAX_LENGTH]; // Frequency counts
int length; // Number of chars to count
int index; // Position of a located char
char inputChar; // Temporary char
Boolean found; // True if char found in list
ifstream dataFile; // Input file to be analyzed
dataFile.open("text.dat");
if ( !dataFile )
{
cout << "** Can't open input file **" << endl;
return 1;
}
GetCharList(charList, length);
ZeroFreqList(freqList, length);
// Count occurrences of desired characters in text on dataFile
dataFile.get(inputChar); // Don't skip whitespace
while (dataFile) // While not EOF...
{ |
|
|
|
|
|