Program in C++ to count the words in given sentence Using user define function
#include<iostream> #include<string.h> #include<conio.h> using namespace std; int Strcountwords(char *str1) { int i,count=1; for(i=0;i<=strlen(str1);i++) { if(str1[i]==' ') count++; } return count; } int main() { char str[100]; cout<<"Enter sentence:-"; cin.getline(str,99); cout<<" Number of words ="<<Strcountwords(str); return 0; }
Output:-
Related Programs --
0 Comments