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 :)
- #include<iostream.h>
- #include<conio.h>
- #include<stdio.h>
- void main()
- {
- clrscr();
- char str[100];
- int w=1;
- cout<<"Please enter a String: ";
- gets(str);
- //Coding by: Snehil Khanor
- //http://WapCPP.blogspot.com
- for (int i=0;str[i]!='\0';i++)
- {
- if(str[i]==' ')
- w++;
- }
- cout<<"There are "<<w<<" words.";
- getch();
- }
2 comments:
thnx a lot for posting this program
bcause i needed it desperately cause it's going 2 come in ma xam.......
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
Post a Comment