View Single Post
Join Date: Jun 2006
Posts: 147
Reputation: Laiq Ahmed will become famous soon enough Laiq Ahmed will become famous soon enough 
Solved Threads: 20
Laiq Ahmed Laiq Ahmed is offline Offline
Junior Poster

Re: Determining the number of unique words in a .txt file

 
0
  #10
Dec 4th, 2008
I tried a different Approach to achieve the same
  1. char* arr = " Hallo WOrld";
  2. char* ptrFirst = arr;
  3. char* ptrIter = arr;
  4. int nWordCount = 0;
  5.  
  6. // Base Condition.
  7. while (isspace (*ptrFirst))
  8. ++ptrFirst;
  9.  
  10. ptrIter = ptrFirst;
  11.  
  12. while (ptrFirst) {
  13.  
  14. while (isalpha(*ptrIter)) {
  15. ++ptrIter;
  16. }
  17.  
  18. ++nWordCount;
  19.  
  20. while (isspace (*ptrIter))
  21. ++ptrIter;
  22.  
  23. if (ptrFirst == ptrIter)
  24. break;
  25.  
  26. ptrFirst = ptrIter;
  27. }
  28.  
  29. cout << nWordCount-1 <<endl;

Hope this approach will help you understand?
Reply With Quote