| | |
word count in borland c++ ??
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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...
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
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)
#include<cctype> if( isspace(string[i]) && !isspace(string[i+1]) ++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
Haven't seen any of your code.. but here is my guess:
like i said.. haven't seen any of your code.. just throwing something your way to think about
C++ Syntax (Toggle Plain Text)
int i=0, word_count=0; //If no text head been read, exit the function if(!myText.size()) return; //Test to see if there are any non-white spaces bool flag=FALSE; while(!Flag && myText.substring(i, 1)) { if(!isspace(myText.substring)) flag=TRUE; i++; } if(flag==FALSE) { cout << "No Text Entered!"; return; } //Perform word count - first word i=0; while(myText.substring(i, 1)) { if(isspace(myText.substring(i, 1)) && !isspace(myText.substring(i+1, 1))) word_count++; i++; } //"First Word" provision word_count++;
like i said.. haven't seen any of your code.. just throwing something your way to think about
•
•
Join Date: Oct 2005
Posts: 6
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- word count (C++)
- I Need Help Writing A Word Count Program In My Python (Python)
- Need Help, basic word count, string manipulation (VB.NET)
- word count (Java)
- I can't implement a word count into my text editor (JAVA) (Java)
Other Threads in the C++ Forum
- Previous Thread: Extracting text from a multi-line Edit Box (win32api using c++)
- Next Thread: New to C++
Views: 4786 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll download dynamic encryption error file forms fstream function functions game givemetehcodez google graph gui iamthwee ifstream input int java lib library lines linkedlist linker loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference return sort string strings struct studio system temperature template templates test text text-file tree unix url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets





