#include <iostream>
#include <string>
using namespace std;
const char SPACE = ' ';
//Function Prototypes
int wordCount(char *); //This function counts and returns the number of words in the string passed into str.
int main()
{
int strCount;
string *str;
cout << "Enter a string of 80 or fewer characters:" << endl;
getline(cin, *str);
strCount = wordCount(*str);
cout << "The number of words in that string: " << strCount;
system ("pause");
return 0;
}
int wordCount(char *str)
{
int count = 0;
for (int i = 0; i<80; i++)
{
while (count == 0)
{
if (str[i] == NULL)
{
return count;
}
else if (str[i] != SPACE)
{
count=count+1;
}
else if (str[i] == SPACE)
{
i++;
}
}
}
}
I've been trying everything I could think of for the last 90 minutes, I've looked all around, and nothing seems to work. Any advice would be greatly appreciated.

New Topic/Question
Reply




MultiQuote



|