adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C++ to count the words in given sentence Using user define function

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 --

  1. Program in C++ to copy one word into another word
  2. Program in C++ to add two string
  3. Program in C++ to convert string Uppercase to Lowercase
  4. Program in C++ to convert string  Lowercase to Uppercase 
  5. Program in C++ to find the length of string using user define function

Post a Comment

0 Comments