A couple more comments
1) If you use a test case that contains two or more spaces in sequence, the histogram will not be correct. I'm guessing all your test cases only have one space between two words.
2) Something that works along the lines;
++x;
if (some_condition)
{
--x;
more_stuff();
} can be expressed more cleanly in the form;
[code]
if (some_condition)
{
more_stuff();
}
else
{
++x;
} Your last code snippet is in that form .....