im writing a program that tokenizes a sentance and then tells how many letters / punctuation marks are in the sentance.
my problem lies where i try to count the letters. when ever my program hits a space it stops. so in essance, its only hitting the first word
here is my whole code.
Code:
#include <iostream>
using namespace std;
#include <iomanip>
using std::skipws;
#include <cstring>
int main()
{
char phrase[50] = {'\0'};
char *tokenPtr;
int x;
int y = 0;
int count = 0;
int count2 = 0;
cout<<"Enter a phrase to be counted and what ever else..\n";
cin.getline (phrase , 50);
cout<<"The sentance entered is....\n";
cout<<phrase<<endl;
tokenPtr = strtok(phrase, " ");
while(tokenPtr != NULL)
{
tokenPtr = strtok(NULL , " ");
count++;
}
cout<<"there are "<<count<<" words in your phrase \n";
for (int i = 0; i <50; i++)
{
if(phrase[i] == '\0')
{
break;
}
count2++;
}
cout<<"number of letters in the phrase is "<<count2<<endl;
return 0;
}