944,041 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5564
  • C++ RSS
Oct 30th, 2005
0

word count in borland c++ ??

Expand Post »
Hi,
Can someone help me in a borland c++ code?
i already have a memo field and i want to count the words, i count the blanks but i have problem when appears 2 or more blanks together and when i write to the second line..
Also can anybody tell me how to print the memo index as a text?
thanks
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dav83 is offline Offline
6 posts
since Oct 2005
Oct 30th, 2005
0

Re: word count in borland c++ ??

sounds like you are on the right track.. counting the number of spaces is probably the easiest way to calculate the number of words in a file.. but as you have already identified.. one could run into trouble if there are multiple spaces in between words..

so why not identify the number of situations where there is a space and the next character is not a space...

C++ Syntax (Toggle Plain Text)
  1. #include<cctype>
  2.  
  3. if( isspace(string[i]) && !isspace(string[i+1])
  4.  
  5. ++word_count;


the above code is not perfect.. you'll have to make considerations for the first word for example.. but should get ye' on the right track
Reputation Points: 237
Solved Threads: 117
Practically a Posting Shark
Clinton Portis is offline Offline
822 posts
since Oct 2005
Oct 30th, 2005
0

Re: word count in borland c++ ??

thank you for your idea, i use the following way of code...
can you help me how to include your idea? thanks

if(myText.SubString(i,1)==" " .........
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dav83 is offline Offline
6 posts
since Oct 2005
Oct 30th, 2005
0

Re: word count in borland c++ ??

Haven't seen any of your code.. but here is my guess:

C++ Syntax (Toggle Plain Text)
  1.  
  2. int i=0, word_count=0;
  3.  
  4. //If no text head been read, exit the function
  5. if(!myText.size())
  6.  
  7. return;
  8.  
  9. //Test to see if there are any non-white spaces
  10. bool flag=FALSE;
  11. while(!Flag && myText.substring(i, 1))
  12. {
  13. if(!isspace(myText.substring))
  14.  
  15. flag=TRUE;
  16. i++;
  17. }
  18.  
  19. if(flag==FALSE)
  20. {
  21. cout << "No Text Entered!";
  22. return;
  23. }
  24.  
  25. //Perform word count - first word
  26. i=0;
  27. while(myText.substring(i, 1))
  28. {
  29.  
  30. if(isspace(myText.substring(i, 1)) && !isspace(myText.substring(i+1, 1)))
  31.  
  32. word_count++;
  33.  
  34. i++;
  35. }
  36.  
  37. //"First Word" provision
  38. word_count++;


like i said.. haven't seen any of your code.. just throwing something your way to think about
Reputation Points: 237
Solved Threads: 117
Practically a Posting Shark
Clinton Portis is offline Offline
822 posts
since Oct 2005
Oct 30th, 2005
0

Re: word count in borland c++ ??

int p=0;
int i,k=1;

AnsiString myText=Memo->Text;
boolean flag=true;

for(i=k;i<=myText.Length();i++)
{
if((myText.SubString(i,1)==" " ||myText.SubString(i,1)=="\t")&& !flag)
{
p++;
flag=True;
}
else
flag=false;
}
k=i+1;

Label1->Caption... bla bla

this is my code, i cannot add your idea with "isspace"
i use borland c++6
can you help me how to use your way in this type of code ?
thanks again for your help
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dav83 is offline Offline
6 posts
since Oct 2005
Oct 30th, 2005
0

Re: word count in borland c++ ??

why not make your own isspace() function then..
Reputation Points: 237
Solved Threads: 117
Practically a Posting Shark
Clinton Portis is offline Offline
822 posts
since Oct 2005
Oct 30th, 2005
0

Re: word count in borland c++ ??

i try but i cant' make a isspace() function for giving in myText.SubString the value " "
can you help me how to?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dav83 is offline Offline
6 posts
since Oct 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Extracting text from a multi-line Edit Box (win32api using c++)
Next Thread in C++ Forum Timeline: New to C++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC