c++ - Figuring out why Word Counter program output is 0 or 1 -
i need figure out bug program. when type hello world am , should count number of spaces, keep getting 0 or 1 . below full program: #include "windows.h" #include <iostream> #include <cctype> using namespace std; //global declarations. //function prototypes. void pause(); void numwords(string&); int numwords(char []); int main() { string userval; numwords(userval); char *constr= new char[userval.length()]; strcpy(constr, userval.c_str()); //string converted c-string. int fin= numwords(constr); cout<< "the number of words in sentence "<< fin<< "."<< endl; delete[] constr; constr= 0; pause(); return 0; } /***************************************functions**********************************************************************/ /*1st function pause program.*/ void pause() { cin.sync();