Count Words : -
- #include "stdafx.h" // Header file for MS VS
- #include <iostream> // Some compiler used < iostream.h>
- #include <conio.h> // header file
- using namespace std ;
- int main ()
- {
- char input[100] ;
- int words ;
- cout << "Enter a string : " ;
- cin.getline(input , 100 , '\n') ;
- if (input[0] == ' ')
- words = 0 ;
- else
- words = 1 ;
- for(int i = 0 ; i < 100 ; i ++)
- {
- if (input[i] == ' ' && input[i + 1] != ' ')
- words ++ ;
- }
- cout << "Words in your enterd string : "<< words ;
- _getch() ; // some compiler use getch()
- return 0 ;
- }
0 comments:
Post a Comment