|
-
February 15th, 2011, 02:32 PM
#1
Help with Maps... Couple Errors
I got this assignment for my class. Its to create and write an interactive program to scan and process an input stream of an ordinary text. Then it checks for punctuation marks, and deletes them from the word. I have all of it written but I'm getting a couple errors and I don't know why it wont work.
Code:
using namespace std;
typedef map<string, int> mapType;
void get_words(map<string, int>&);
void print_words(const map<string, int>&);
void clean_entry(const string&, string&);
/****************************************************************
FUNCTION: Main
ARGUMENTS: None
RETURNS: None
NOTES: Calls the subroutine get_words and then get_words
calls clean_entry
****************************************************************/
int main()
{
map<string, int> wordList;
get_words(wordList);
print_words(wordList);
return 0;
}
/****************************************************************
FUNCTION: Void get_words
ARGUMENTS: map string, integer &
RETURNS: None
NOTES: Routine gets a word from the input stream and then
cleans its punctuation marks.
****************************************************************/
void get_words(map<string, int>& wordList)
{
string originalWord, cleanedWord;
while (cin >> originalWord)
{
clean_entry(originalWord, cleanedWord);
if (cleanedWord.length() > 0)
wordList[cleanedWord]++;
cleanedWord = "";
}
}
/****************************************************************
FUNCTION: Void clean_entry
ARGUMENTS: const map string&, string&
RETURNS: nothing
NOTES: Cleans a word from its punctuation marks. The
first argument is the original word from input
stream and the second contains the same word
after cleaning.
****************************************************************/
void clean_entry(const string& source, string& target)
{
int p1 = 0, p2;
while(!isalnum(source[p1]) && p1 < source.length()) p1++;
p2 = p1;
while(isalnum(source[p2])&& p2 < source.length()) p2++;
if( p2 == p1 ) target = "";
else target = source.substr(p1, p2-p1);
return;
}
/****************************************************************
FUNCTION: Void print_words
ARGUMENTS: const map string int &
RETURNS: None
NOTES: Prints the final list of words and their frequencies
It also prints hte number of nonempty words
and the number of distinct words in the input stream
****************************************************************/
void print_words(const map<string, int>& wordList, int nemptyw)
{
int i = 0;
cout << "Nonemmpty words : " << nemptyw << endl;
cout << "Distinct words : " << wordList.size() << endl;
for(mapType::const_iterator it = wordList.begin(); it != wordList.end(); ++it)
{
cout << setw (15);
cout << setiosflags (ios_base::left);
cout << it->first << " - " << it->second << " ";
if (++i >= 3 )
{
i = 0;
cout << endl;
}
}
cout << endl;
}
The Errors:
In function ‘void clean_entry(const std::string&, std::string&)’:
prog3.cc:105: warning: comparison between signed and unsigned integer expressions
prog3.cc:108: warning: comparison between signed and unsigned integer expressions
not sure what that is. When i nano prog3.out it shows...
-bash: prog3.exe: command not found
Anyone can help me out?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|