W.A.P. C++

WAP | CPP | Programs in C++ | C++ Solutions

Write a program to count number of words in a line


A line is taken from user and number of words is calculated..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<stdio.h>
  4. void main()
  5. {
  6. clrscr();
  7. char str[100];
  8. int w=1;
  9. cout<<"Please enter a String: ";
  10. gets(str);
  11. //Coding by: Snehil Khanor
  12. //http://WapCPP.blogspot.com
  13. for (int i=0;str[i]!='\0';i++)
  14. {
  15. if(str[i]==' ')
  16. w++;
  17. }
  18. cout<<"There are "<<w<<" words.";
  19. getch();
  20. }

2 comments:

Sweeti March 14, 2011 at 8:32 AM  

thnx a lot for posting this program
bcause i needed it desperately cause it's going 2 come in ma xam.......

Praful Agarwal September 20, 2013 at 3:55 PM  

Hi, yeah this article is actually good and very helpful to practically implement the program on count the number of words in a line I have learned lot of things from it.
Career Mint

Search

About WAP C++

Here you'll find a wide range of programs' solution ranging from beginer level to advanced level.
All programs here are made, compiled and tested by me..and are running absolutely fine.. still if you find any bug in any program do let me know :)

Followers

Subscribe via email

Enter your email address:

Delivered by FeedBurner

my Binary Log

Recent Posts

Blog Archive



eXTReMe Tracker