GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Jun-2008, 19:30
ps02.psp ps02.psp is offline
New Member
 
Join Date: Jun 2008
Posts: 2
ps02.psp is on a distinguished road
Exclamation

Word counting function for c++


this is a question on a test in my class so it has to be specifically like this:
well I've tried to compile it and I've come across an 2 errors regarding the p.find i have
in my for loop ---- error C2661: 'find' : no overloaded function takes 2 parameters
A friend somewhat made the loop for me but i really need more help understanding how to make a loop that works sucessfully

countWord(String p, String w)
the first parameter p is to hold the paragraph
the second is to hold the word you want counted
the function is suppose to return a integer value of 0 or more depending on how often your word is found in the paragraph

#include <iostream.h>
#include <lvp\string.h>

int countWord(String &p, String &w)
{
int counter, spacePos, nextspacePos = 0;
for (int i = 0; i < p.length(); i++)
{
spacePos = p.find(p.substr(spacePos, p.length() ), ' ');
nextspacePos = p.find(p.substr(spacePos, p.length()), ' ');
if (w == p.substr(spacePos + 1, w.length()))
{
counter++;
i = nextspacePos;
}
}
return(counter);
}

int main()
{
String p;
String w;

cout << "Type in a paragrah below" << endl;
getline (cin, p);
cout << "Type in a word you woud like to have counted: ";
cin >> w;

cout << countWord(p, w);
return(0);
}
  #2  
Old 04-Jun-2008, 20:18
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,303
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Word counting function for c++


Quote:
Originally Posted by ps02.psp
this is a test question...

Since you didn't ask a question, I'll ask a couple:

1. Have you tried to compile it?
2. How will you test it?
3. What kind of help would you like to get?


Regards,

Dave
  #3  
Old 04-Jun-2008, 20:28
ps02.psp ps02.psp is offline
New Member
 
Join Date: Jun 2008
Posts: 2
ps02.psp is on a distinguished road

Re: Word counting function for c++


oops lol iam just lost today here is what i really meant:
It is a test question as in my teacher was kind enough to redo a question i messed up on a test. well I've tried to compile it and I've come across an 2 errors regarding the p.find i have
in my for loop ---- error C2661: 'find' : no overloaded function takes 2 parameters
A friend somewhat made the loop for me but i really need more help understanding how to make a loop that works sucessfully
  #4  
Old 04-Jun-2008, 21:17
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,303
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Word counting function for c++


Quote:
Originally Posted by ps02.psp
...
in my for loop ---- error C2661: 'find' : no overloaded function takes 2 parameters
A friend ...

Hmmm... the code that I copied from your first post had no main() program, and ho include files, and nothing about "find," so I guess you must have edited it somewhat (or, maybe I just missed something...It wouldn't be the first time.)

Anyhow, since your code now includes a non-standard header, which, presumably has typedefs and/or class definitions for String, and since I don't have any way of knowing how to work with it, I'm done.

Sorry.

Maybe someone else...


Regards,

Dave
  #5  
Old 06-Jun-2008, 07:14
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve

Re: Word counting function for c++


You will only get help after we have understand your problem.
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
run script command on ns2.26 newbie06 Computer Software Forum - Linux 66 16-Jan-2010 11:53
Flex and bison coding lucky88star C++ Forum 5 24-Dec-2007 12:57
Need Help with input files. Efferus C++ Forum 2 24-Nov-2007 17:19
Need help getting started on a database search program Heresy C Programming Language 13 03-May-2006 14:56
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 14:12

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:14.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.