This repository was archived by the owner on Apr 2, 2024. It is now read-only.
forked from ASULabs/op_Lab-Work-7
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
64 lines (55 loc) · 1.19 KB
/
main.cpp
File metadata and controls
64 lines (55 loc) · 1.19 KB
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
#include <iostream>
#include <string.h>
using namespace std;
void input();//String input
int parse_words();//Parse array of words out of string,returns count of words
void input_l(int*);//Input word length
void output_count(int,int);//Output count of words longer than input length
char s[100];//input string
char words[10][10];//array of words
int main() {
int k;//words count
input();
k = parse_words();
int l;//user input length
input_l(&l);
output_count(k,l);
return 0;
}
void input()
{
puts("Input string not longer than 100 symbols,each word not longer than 10 symbols");
gets(s);
}
void input_l(int *m)
{
puts("Input word length");
cin >> *m;
}
int parse_words()
{
int k=0;
char *p;
char delimiters[4]=" ,.";
puts("Words in the string");
p=strtok(s,delimiters);
while (p != NULL)
{
strcpy(words[k],p);
puts(p);
p=strtok(NULL,delimiters);
k++;
}
cout << "Word count " << k << endl;
return k;
}
void output_count(int k,int l)
{
int c = 0;
for (int i = 0;i < k;i++)
{
if (strlen(words[i]) > l)
c++;
}
cout << "Words longer than " << l << ": " << c <<endl;
}