A
ashmangat
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] != '\0')
{
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.
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] != '\0')
{
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.