What's new

C++ Builder - any pro's in the house?

Jaz

Ex-Mod
Basically having a bit of trouble with this stupid ass Uni assignment.

Anyone compliant in C++ Builder?
 

smcd

Active member
What's the trouble? I'm no "pro" but have had to use it @ the uni here a couple times myself. (I don't really like it much ;))
 
OP
Jaz

Jaz

Ex-Mod
Basically I've written a simple notepad program. One of the tasks in it was to include a functional word count. That's the only part of it I can't work out.
 

Niggy G

HTAFC will rise again!!!
This is not specific to C++ Builder but…

You could count the spaces with instr (actually I can't remember if it is this function) and add 1

"just like this" 2 spaces 3 words

There would be a problem with double spaces so you would have to have a temporary variable that stored the last character. If the current char is a space it checks the variable to see if the last char was a space, if so the count is not incremented.

You would also have to remove any beginning and ending spaces from the string you are ‘word counting’.

Then there is the thinking about what you want to include in your word count, would you want the following to be words, ‘3rd’ ‘&’. For simplicity I would say anything with a space either side of it is a word.

I suppose its more complicated than at a first glance.

EDIT: Looking at the way word does its word count, it includes as I said anything with a space either side of it is. e.g. " ^^^ "
 
Last edited:

smcd

Active member
Even though you've got it covered, you could check out the source to "wc," a word/line/character count program for *nix :)
 

Top