If you are just looking to manipulate some strings, C++ might not be the best choice of languages.
I recently got into PERL, which was originally built to focus on I/O and string manipulation. You should look into it if you have little projects like this often.
It's quick, easy, portable, not incredibly powerful, but very useful for common tasks. For example, I wrote this pretty quickly (in half my lunch break).
wordcount.pl wrote:
##### open the file and read the contents into one big string
open (FILEHANDLE, @ARGV[0]);
for ($line_number=1;<FILEHANDLE>;$line_number++)
{$contents = $contents . $_;}
close (FILEHANDLE);
##### remove punctuation and extra whitespace
$contents =~ s/\W+/ /g;
##### parse each word into its own array element
@word_list = split / /, $contents;
##### sort the list
@word_list = sort @word_list;
##### count the repeated elements
foreach $word (@word_list)
{
$size_of_results = @results;
if (@results[$size_of_results-1] eq $word & $size_of_results >0)
{
@count[$size_of_results-1] ++;
}
else
{
@results[$size_of_results] = $word;
@count[$size_of_results] = 1;
}
}
##### print the results
for ($c=0;$c<=$size_of_results;$c++)
{
print "@count[$c] : @results[$c]\n";
}
This does about what you want to do (I think).
If you want to install
perl and run it from the command line like this
>perl wordcount.pl transcriptfile.txt
let me know how it works out.
Edited, Fri Oct 8 14:00:18 2004 by highRfrequenC