-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram107.c++
More file actions
60 lines (54 loc) · 991 Bytes
/
program107.c++
File metadata and controls
60 lines (54 loc) · 991 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<iostream>
#include<string.h>
#include<cstring>
using namespace std;
char* trim(char str[],int l){
char temp[100];
int i=0,j=0;
while(str[i]==' '){
i++;
}
for(j=0,i;i<l;i++,j++){
temp[j]=str[i];
}
j=l-1;
while(temp[j]==' '){
temp[j]='\0';
j--;
}
return temp;
}
int word_count(char str[],int l){
int c=0;
for(int i=0;i<l;i++){
if(str[i]==' '){
if(str[i+1]==' '){
continue;
}
else{
c++;
}
}
}
return c;
}
void function(char str[]){
char temp[100];
int c;
int l=strlen(str);
trim(str,l);
l=strlen(str);
int c=word_count(str,l);
char s[c][50];
for(int i=0;i<c;i++){
for(int j=0;str[j] ;j++){
s[i][j]=str[j];
}
}
}
int main(){
char str[100];
cout<<"Enter a string:";
cin.getline(str,100);
function(str);
}