Skip to content

Pro Programming

Professional way of Programming

  • Home
  • C MCQs
  • C/C++
  • Java
  • Python
  • MySQL
  • Online Compiler
  • Topics
    • Arrays
    • Strings
    • Link Lists
    • Trees
    • Shapes
    • Articles
    • Games
    • Projects

C++ Program to Count number of Words in String

PROGRAM:

#include<iostream>
using namespace std;

int main()
{

char str[100];
int w=1;
cout<<"Please enter a String: ";
gets(str);

for (int i=0;str[i]!='';i++)
{
if(str[i]==' ')
w++;
}
cout<<"There are "<<w<<" words.";
return 0;
}

 

OUTPUT:

count words in string

Related Posts:

  • Count number of equal pairs in a String in C++
  • Count pairs of non-overlapping palindromic sub-strings of the given string
  • Python program to count number of each Vowel
  • Java String to String Array Example
  • How to count number of non repeating digits in a Range C++
  • Number of substrings of binary string containing K ones
  • Python program to check if String is Palindrome or not
  • Java Program to Display String in Rectangle
  • Program to Check if a number is Palindrome Number C++
  • Program to check if number is Armstrong Number in Python
  • Java Convert int Array To String Example
  • Java Reverse String Array Example
  • Java Sort String Array Example
  • Java Stacktrace to String Example
  • Java Date to String Example
Categories string
Post navigation
Union and Intersection of Arrays C++
Rotate Image by 90 degree in C++

Leave a Comment Cancel reply

Must See Content

  • Count number of equal pairs in a String in C++
  • Count pairs of non-overlapping palindromic sub-strings of the given string
  • Python program to count number of each Vowel
  • Java String to String Array Example
  • How to count number of non repeating digits in a Range C++
  • Number of substrings of binary string containing K ones
  • Python program to check if String is Palindrome or not
  • Java Program to Display String in Rectangle
  • Program to Check if a number is Palindrome Number C++
  • Program to check if number is Armstrong Number in Python

Recent Comments

  • David Bolton on Last Minute Notes: C and C++
  • Alisha Ross on Some mind blowing facts about Computers
  • Binary Search Tree implementation in C++ - Pro Programming on Program to check if Tree is Binary Search Tree C++
  • C++ program to implement AVL Tree - Pro Programming on Red Black-Tree(RB-Tree) implementation in C++
  • Program to Find Perfect Number in Python - Pro Programming on Program to find Perfect Number Program in C++
  • Email
  • Facebook
  • Twitter

Related Posts:

  • Count number of equal pairs in a String in C++
  • Count pairs of non-overlapping palindromic sub-strings of the given string
  • Python program to count number of each Vowel
  • Java String to String Array Example
  • How to count number of non repeating digits in a Range C++
  • Number of substrings of binary string containing K ones
  • Python program to check if String is Palindrome or not
  • Java Program to Display String in Rectangle
  • Program to Check if a number is Palindrome Number C++
  • Program to check if number is Armstrong Number in Python

Recent Posts

  • How to use MySQLDump effectively for backups
  • Top 10 Games for Beginners to learn programming the easy way
  • A simple Zombie War Game in C++
  • Mobile Numeric Keypad Problem: Solution in C++
  • Last Minute Notes: C and C++
  • JavatPoint Offline version Download Free
  • How to count number of non repeating digits in a Range C++
  • C++ Program to check if word exists in Grid or not
  • Top Cryptocurrency list of 2021
  • C Program to Implement Coppersmith Freivald’s Algorithm
© 2020 | ProProgramming | About | Contact US | Privacy Policy