-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstr1.c
66 lines (59 loc) · 1.3 KB
/
str1.c
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
61
62
63
64
65
66
#include<stdio.h>
void hmw(char str[]){
int i, j = 0;
for(i = 0; str[i] != '\0'; i++){
if(str[i] == ' '){
j++;}
}
j++;
printf("The sentence contain %d words.\n", j);
}
void lew(char str0[]){
int x, y, n=0, m=0;
int *p[50]={0};
for(x = 0; str0[x] != '\0'; x++){
if(str0[x] == ' '){
*(p+n) = x - m;
m = x;
m++;
n++;
}
}
*(p+n) = x - m;
printf("\nThe length of each word is:\n");
for(y = 0; y < n + 1; y++){
printf("%d ", *(p+y));}
printf("\n");
}
void ncl(char str2[]){
int a, b, d=0, k, t[50]={0};
char c[50]={0};
for(a = 0; str2[a] != '\0'; a++){
if(str2[a] == ' ' || str2[a] == '0'){
continue;
}
for(b = a + 1; str2[b] != '\0'; b++){
if(str2[a] == str2[b]){
str2[b] = '0';
t[d]++;
}
}
c[d] = str2[a];
t[d]++;
d++;
str2[a] = 0;
}
printf("\nThis is the frequency of each symbol appear:\n");
for(k = 0; c[k] != '\0'; k++){
printf("%c:%d\n", c[k], t[k]);
}
}
int main(){
char str1[100];
printf("Please input your sentence:\n");
gets(str1);
hmw(str1);
lew(str1);
ncl(str1);
return 0;
}