word count in borland c++ ??

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2005
Posts: 6
Reputation: dav83 is an unknown quantity at this point 
Solved Threads: 0
dav83 dav83 is offline Offline
Newbie Poster

word count in borland c++ ??

 
0
  #1
Oct 30th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 481
Reputation: Clinton Portis is on a distinguished road 
Solved Threads: 58
Clinton Portis's Avatar
Clinton Portis Clinton Portis is offline Offline
Posting Pro in Training

Re: word count in borland c++ ??

 
0
  #2
Oct 30th, 2005
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...

  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
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 6
Reputation: dav83 is an unknown quantity at this point 
Solved Threads: 0
dav83 dav83 is offline Offline
Newbie Poster

Re: word count in borland c++ ??

 
0
  #3
Oct 30th, 2005
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)==" " .........
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 481
Reputation: Clinton Portis is on a distinguished road 
Solved Threads: 58
Clinton Portis's Avatar
Clinton Portis Clinton Portis is offline Offline
Posting Pro in Training

Re: word count in borland c++ ??

 
0
  #4
Oct 30th, 2005
Haven't seen any of your code.. but here is my guess:

  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
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 6
Reputation: dav83 is an unknown quantity at this point 
Solved Threads: 0
dav83 dav83 is offline Offline
Newbie Poster

Re: word count in borland c++ ??

 
0
  #5
Oct 30th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 481
Reputation: Clinton Portis is on a distinguished road 
Solved Threads: 58
Clinton Portis's Avatar
Clinton Portis Clinton Portis is offline Offline
Posting Pro in Training

Re: word count in borland c++ ??

 
0
  #6
Oct 30th, 2005
why not make your own isspace() function then..
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 6
Reputation: dav83 is an unknown quantity at this point 
Solved Threads: 0
dav83 dav83 is offline Offline
Newbie Poster

Re: word count in borland c++ ??

 
0
  #7
Oct 30th, 2005
i try but i cant' make a isspace() function for giving in myText.SubString the value " "
can you help me how to?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 4786 | Replies: 6
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC