Hello,
I am needing to accept a string of characters from the user, count the number of words, and the average number of letters per word. I've got it about half way done, but feel I'm going in the wrong direction. Any suggestions would be appreciated.
Thanks,
George
Code:
#include <iostream.h>
#include <string>
using namespace std;
int wordCount(int *ptrStr); //Function prototype
int main(void)
{
char number[81];
int average;
string size;
int *ptrString;
cout<<"Please enter a string, 80 characters or fewer: "<<endl;
cin.getline(number,81);
*ptrString=int (number);
size=number;
cout<<size.length()<<endl;
wordCount(ptrString);
average=int(wordCount(ptrString)) / size;
cout<<number<<" "<<wordCount(ptrString);
return 0;
}
int wordCount(int *ptrString)
{
int index=0;
int word=0;
while (index<*ptrString)
{
index++;
if (ptrString[index] == ' ')
ptrString[index]= '\0';
word++;
}
return word;
}