C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Need Help, Can you find the error???

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
ashmangat@yahoo.com
Guest





PostPosted: Mon Nov 21, 2005 10:34 am    Post subject: Need Help, Can you find the error??? Reply with quote



Hi!
now on the chapter "string-class" My assignment is below Word Counter:
Write a function that accepts a pointer to a C-String as an argument
and returns the number of words contained in the string. For instance,
if the string argument is "Four score and seven years ago" the function

should return the number 6. Demonstrate the function in a program that
asks the user to input a string and then passes it to the function. The

number of words
in the string should be displayed on the screen.It should also display
the average number of letters in each word.
Here is the begining of my program
I am getting two errors: LNK2001: unresolved external symbol "char
__cdecl wordCount(char)" (?wordCount@@YADD@Z)
Debug/1.exe : fatal error LNK1120: 1 unresolved externals
---------------------------------------------------------------------------ญญ-----------------

#include <iostream>
#include <string>
#include <iomanip>
#include <ctype.h>
using namespace std;
char wordCount(char );
int main()
{
char cstring[81];


cout << "nEnter a string, 80 or fewer characters:n";
cin.getline(cstring, 81);
cout << "nThe number of words in that string: ";
cout << wordCount(cstring[81]) << endl;
return 0;



}


char wordCount(char cstring[81])
{
int index = 0;
int word = 0;
while (cstring[index] != '')
{
if (isspace(cstring[index]))
{
while (isspace(cstring[index]))
{
index++;
}
}
if (isalnum(cstring[index]))
{
word++; //we must be in a word
while(islower(cstring[index]))
{
word++;
}
}
index++;
}
return cstring[word];


}
---------------------------------------------------------------------------ญญ

can anyone find the error and perhaps make a suggestion to fix it.
------
Ash


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Ulrich Eckhardt
Guest





PostPosted: Mon Nov 21, 2005 5:52 pm    Post subject: Re: Need Help, Can you find the error??? Reply with quote



[email]ashmangat (AT) yahoo (DOT) com[/email] wrote:
Quote:
LNK2001: unresolved external symbol
"char __cdecl wordCount(char)"

char wordCount(char );
[...]
char wordCount(char cstring[81])

The first does not match the second. Also, the second is a dangerous lie: in
fact, this function takes a pointer to char, it does not (as it seems) take
an array. That means that this function could modify the values via the
pointer you passed into it.

I'm pretty sure it was already mentioned in the other groups you posted to
that you should use std::string and std::getline( std::cin, some_string)
instead of a fixed size buffer, but that is a different problem.

Also, about the isspace() you use, read James Kanze's response to the recent
thread "syntax analyzer problem!".

Uli


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.