Announcement

Collapse
No announcement yet.

Borland's C++ Builder - Word Count?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Borland's C++ Builder - Word Count?

    Hi there guys,

    I'm trying to add a word count to an application i have made. The application is just a simple notepad. A feature im trying to add is a word count.

    The text i want to count is stored in a memo box called 'Memo'.

    Here is the logical way i think the code should work, can anyone help me turn this into C++.
    Code:
    char *c = Memo->Lines.c_str();
    count = 0;
    For (i=0;i=MemoLengthInCharacters;i++)
       {
       If(c[i]=" " && c[i+1]!=" ")
          {
          count++;
          }
       }
    Somehow i have to turn the Memo->Lines into an array of charcters where the first character will = c[i] and the last will equal c[i+length]. Is their a command for doing this?

    Hopefully if i can figure this out i should be able to do the rest...

    Appreciation in advance

    P.s. I'm only just starting out with C++ so please take that into consideration

  • #2
    Actually ... the c_str() function does just that. It takes a c++ std::string container and converts it into standard c character string, which in nature is just that, an indexed array of characters that make up a string. Another way you might tackle it is by having the compiler handle searching for each space instead of manually looping through and comparing each character; since you're using c++ you should look into the the find function.

    I think you'll enjoy http://www.cppreference.com/.
    if it gets me nowhere, I'll go there proud; and I'm gonna go there free.

    Comment

    Working...
    X