![]() |
|
#1
|
|||
|
|||
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
|
|||
|
|||
Re: Word counting function for c++Quote:
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
|
|||
|
|||
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
|
|||
|
|||
Re: Word counting function for c++Quote:
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
|
|||
|
|||
Re: Word counting function for c++You will only get help after we have understand your problem.
|
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
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