-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram105.c++
More file actions
46 lines (44 loc) · 834 Bytes
/
program105.c++
File metadata and controls
46 lines (44 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Write a function to count the words in the string.
#include<iostream>
using namespace std;
int function(char a[100],int l){
char b[100];
int j=0,c=0,i=0;
while(a[j]==' '){
j++;
}
for(int i=0;i<l;i++){
b[i]=a[j];
j++;
}
for(int i=l-1;a[i]==' ';i--){
b[i]='\0';
}
l=0;
c=0;
while(b[l]!='\0'){
l++;
}
for(int i=0;i<l;i++){
if(b[i]==' '){
if(b[i+1]==' ')
{
continue;
}
else{
c++;
}
}
}
cout<<"There are total numbers of words in given string are:"<<c+1;
}
int main(){
char a[100];
int l=0,result;
cout<<"Enter the string:";
cin.getline(a,100);
while(a[l]!='\0'){
l++;
}
function(a,l);
}