Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,200 --> 00:00:06,210
So I hope you got yourself some time to think about the solution, and now what I want us to do is to
2
00:00:06,210 --> 00:00:11,370
start solving the exercise so we have to find down how many words.
3
00:00:11,400 --> 00:00:14,490
Let's just point out these here.
4
00:00:14,550 --> 00:00:16,080
And what was it?
5
00:00:16,350 --> 00:00:17,050
Find out.
6
00:00:17,070 --> 00:00:23,130
Find how many words there are in a string.
7
00:00:23,340 --> 00:00:23,600
OK.
8
00:00:23,820 --> 00:00:28,710
So the first thing that we were asked to do is to create to create a string.
9
00:00:28,740 --> 00:00:32,980
So let's use something like this Charlot's year sentence.
10
00:00:33,030 --> 00:00:33,240
OK.
11
00:00:33,660 --> 00:00:35,050
So this will be a string.
12
00:00:35,070 --> 00:00:37,020
Let's make it a size 30.
13
00:00:37,380 --> 00:00:43,920
And basically, we declared an array of characters that will be used to hold a string.
14
00:00:44,190 --> 00:00:48,720
So the next thing that we are going to do is we are going to print some nice message.
15
00:00:48,720 --> 00:00:50,450
So to the user printer.
16
00:00:51,270 --> 00:00:54,560
Please, please enter.
17
00:00:54,720 --> 00:00:55,340
Enter.
18
00:00:55,470 --> 00:01:02,070
Let's say a string, a string or some text string or some text.
19
00:01:02,460 --> 00:01:08,130
And now what we are going to do is we are going to use the get this function to read the string from
20
00:01:08,130 --> 00:01:08,590
the user.
21
00:01:08,640 --> 00:01:09,730
So get us.
22
00:01:09,930 --> 00:01:13,680
And here we will have ah, we will have what we will have.
23
00:01:13,860 --> 00:01:14,900
The sentence itself.
24
00:01:14,910 --> 00:01:15,190
Right.
25
00:01:15,270 --> 00:01:20,730
Maybe you're more familiar with using CHA as the arm to create a string.
26
00:01:20,760 --> 00:01:22,470
But this is just the name.
27
00:01:22,590 --> 00:01:24,270
We will simply use it here.
28
00:01:24,930 --> 00:01:31,440
So now once we've read the string from the user, from the console application, it will be stored inside
29
00:01:31,590 --> 00:01:37,350
of this array of characters representing a string with a null character at the end of it.
30
00:01:37,770 --> 00:01:44,820
And now what we are going to do is simply to assume let's just for the beginning, will there take the
31
00:01:44,820 --> 00:01:46,350
text that we use there?
32
00:01:46,350 --> 00:01:46,890
What was it?
33
00:01:47,760 --> 00:01:49,890
Hi, my name.
34
00:01:50,250 --> 00:01:51,000
Something like this.
35
00:01:51,060 --> 00:01:53,970
My name is glad if I'm not mistaken.
36
00:01:54,240 --> 00:01:57,550
So this was our previous text or a previous string.
37
00:01:57,720 --> 00:02:02,100
And what we will assume that we have a what will be our separate.
38
00:02:02,100 --> 00:02:06,540
There is this space and that we have one space between every word.
39
00:02:06,570 --> 00:02:12,000
So this is kind of our assumption will also create two additional variables.
40
00:02:12,030 --> 00:02:18,870
Let's call it something like count words, which will represent the number of words.
41
00:02:19,290 --> 00:02:26,350
And we will specify that it will be zero and we will use an additional variable.
42
00:02:26,400 --> 00:02:27,160
It's C I.
43
00:02:27,180 --> 00:02:31,830
That will help us to iterate over each character in this string.
44
00:02:32,010 --> 00:02:36,240
So we know that we can run are basically on these string.
45
00:02:36,300 --> 00:02:37,810
Let's let's create something like this.
46
00:02:37,830 --> 00:02:38,000
OK.
47
00:02:38,280 --> 00:02:40,330
So let's also add in it.
48
00:02:42,140 --> 00:02:43,090
No, no.
49
00:02:43,110 --> 00:02:46,050
We don't need these and we just will use these for a loop.
50
00:02:46,080 --> 00:02:48,070
So four equals two zero.
51
00:02:48,090 --> 00:02:51,510
As long as I is less than then what then.
52
00:02:51,510 --> 00:02:54,900
SDR land is your land of sentence.
53
00:02:54,930 --> 00:02:55,150
OK.
54
00:02:55,230 --> 00:03:02,110
So we know we will run from my equals to zero until the last time.
55
00:03:02,220 --> 00:03:03,920
The backslash zero character.
56
00:03:04,110 --> 00:03:08,130
And we will increment I by one on each iteration.
57
00:03:08,790 --> 00:03:17,190
And we know that if we want to use the SDL in function we should include include the String Dodd H library
58
00:03:17,190 --> 00:03:18,300
that we've just mentioned.
59
00:03:18,550 --> 00:03:26,010
Now what we are going to do in these for a loop is simply to check where we have the space character.
60
00:03:26,070 --> 00:03:32,700
So whenever we come across this space character, we will assume that a word that some word has ended
61
00:03:32,760 --> 00:03:34,830
and a new word has started.
62
00:03:35,100 --> 00:03:40,050
So we will simply do something like these will use this simple condition if sentence.
63
00:03:40,230 --> 00:03:40,680
Sen.
64
00:03:40,860 --> 00:03:41,610
Sen.
65
00:03:41,820 --> 00:03:44,340
Dan's sentence at Index I.
66
00:03:44,400 --> 00:03:48,840
So if a given character equals to a space character.
67
00:03:49,110 --> 00:03:52,110
So in this case we are going to implement the count.
68
00:03:52,160 --> 00:03:53,310
Words by one.
69
00:03:53,310 --> 00:03:54,990
So count horse plus plus.
70
00:03:55,140 --> 00:04:01,050
And this way what we are going to do is simply to either read over all of the string we've got from
71
00:04:01,050 --> 00:04:07,230
the user and to count the number of the number of space characters in this string.
72
00:04:07,560 --> 00:04:12,990
And based on this result, we will assume that though there will be these exact number of words.
73
00:04:13,170 --> 00:04:15,010
So that PIN B will work.
74
00:04:15,060 --> 00:04:15,360
OK.
75
00:04:15,420 --> 00:04:21,300
But let's say it was just kind of our assumption that there will be just one space character.
76
00:04:21,540 --> 00:04:23,580
But let's assume that that's the case.
77
00:04:23,580 --> 00:04:31,310
And we will also we will also use here that print off-line to print the results of print print F on
78
00:04:31,330 --> 00:04:39,480
the total amount, total amount of Maude's in percentage as equals to.
79
00:04:39,670 --> 00:04:43,030
Are centage d backslash n in hearings that of percentages.
80
00:04:43,170 --> 00:04:45,240
We are going to specify the sentence.
81
00:04:45,510 --> 00:04:47,070
And instead of the percentage.
82
00:04:47,610 --> 00:04:51,060
We are going to specify the count words.
83
00:04:51,120 --> 00:04:51,480
OK.
84
00:04:51,670 --> 00:04:53,910
The number of words in this string.
85
00:04:54,120 --> 00:04:59,830
But the thing that interests us here is should we add additional last plus oken.
86
00:05:00,080 --> 00:05:06,650
And the increment the count of words by one, because if suppose we were, we had only two words.
87
00:05:06,950 --> 00:05:09,740
So it will look like this high mile, let's say.
88
00:05:10,250 --> 00:05:15,650
And we will simply see that there is just one space character in this string.
89
00:05:16,010 --> 00:05:22,250
So that's why we want to we know that there is a separator and meaning that it will count the one on
90
00:05:22,250 --> 00:05:22,730
the left.
91
00:05:22,760 --> 00:05:24,170
And also the one on the right.
92
00:05:24,200 --> 00:05:28,940
So that's why we will use outside of the for a loop outside the slope.
93
00:05:28,950 --> 00:05:32,240
We will use also the last incrimination by one.
94
00:05:32,600 --> 00:05:36,980
So now we've we will print this result of the screen.
95
00:05:36,980 --> 00:05:40,400
We will see the number of words in our text.
96
00:05:40,460 --> 00:05:42,500
So let's try to build and run it.
97
00:05:42,620 --> 00:05:49,430
So go here to the Beeld and Iran and let's say hi, my name.
98
00:05:49,490 --> 00:05:50,600
My name is.
99
00:05:51,290 --> 00:05:51,620
OK.
100
00:05:52,040 --> 00:05:54,440
And we expect that the result will be five.
101
00:05:54,590 --> 00:05:54,920
Right.
102
00:05:55,580 --> 00:06:00,110
So we can see that if we write run this program.
103
00:06:00,290 --> 00:06:03,920
Total amount of words in hi my name is Vlada equals to five.
104
00:06:04,310 --> 00:06:06,980
Not exactly specified correctly.
105
00:06:07,000 --> 00:06:08,850
Let's just do something like these.
106
00:06:08,850 --> 00:06:13,160
I don't know, just use it to specify that this is our strength.
107
00:06:13,190 --> 00:06:14,840
So let's build in running once again.
108
00:06:15,170 --> 00:06:15,720
Hi.
109
00:06:15,950 --> 00:06:17,900
My name is Vlad.
110
00:06:18,350 --> 00:06:25,880
And let's see so we can see here that the total amount of water in hi my name is Vlad equals to five.
111
00:06:26,090 --> 00:06:27,980
And that's exactly what we expected.
112
00:06:28,370 --> 00:06:37,030
We expected to count the words based on this space separator that we know that a space character separates
113
00:06:37,040 --> 00:06:39,140
between different words.
114
00:06:39,620 --> 00:06:48,530
And what basically interests here, me and also probably you, is the fact that there is a lot of strings
115
00:06:48,560 --> 00:06:56,210
that probably will not be so conventional and just use one space character like we counted here between
116
00:06:56,210 --> 00:06:57,380
two different words.
117
00:06:57,650 --> 00:07:01,970
So, for example, we may have a space at the beginning, for example.
118
00:07:02,070 --> 00:07:03,260
This is our string, right?
119
00:07:03,290 --> 00:07:04,730
Previously it was like this.
120
00:07:05,240 --> 00:07:10,760
And I tell you that there isn't a chance that a string starts with the space character.
121
00:07:10,790 --> 00:07:11,010
Right?
122
00:07:11,060 --> 00:07:12,710
Maybe by mistake, maybe no.
123
00:07:13,190 --> 00:07:17,660
And in this case, our program will not return the correct result.
124
00:07:17,810 --> 00:07:20,510
And also, it may be on it at the end of the string.
125
00:07:20,570 --> 00:07:20,930
OK.
126
00:07:20,990 --> 00:07:25,700
You may have here a space character or maybe between two different words.
127
00:07:25,700 --> 00:07:28,040
You may have a space character or two.
128
00:07:28,250 --> 00:07:30,290
So this program, it works.
129
00:07:30,410 --> 00:07:30,840
Okay.
130
00:07:30,890 --> 00:07:37,790
If for for the basic case where you can assume that there is only one space character between two words
131
00:07:38,030 --> 00:07:44,450
and a space character appears does not appear at the end or at the beginning of a string.
132
00:07:44,660 --> 00:07:51,290
So basically what I want you to do is to upgrade, to develop some program, since you know how these
133
00:07:51,290 --> 00:07:52,130
program works.
134
00:07:52,490 --> 00:08:00,920
I want you to think of how would you upgrade these kind of simple program to support also these, let's
135
00:08:00,920 --> 00:08:09,200
say, end end cases where you have to find out the number of words and where I can be, where there
136
00:08:09,200 --> 00:08:14,090
can be a space character at the beginning, at the end, or maybe between them there will be, let's
137
00:08:14,090 --> 00:08:16,460
say, multiple character space characters.
138
00:08:16,730 --> 00:08:20,300
So how what what what would you change in this program?
139
00:08:20,540 --> 00:08:21,590
So what will work?
140
00:08:22,880 --> 00:08:24,710
Also for all cases.
141
00:08:24,830 --> 00:08:27,290
So that's your task for today.
142
00:08:27,440 --> 00:08:34,850
Your task is to develop this program and to try try different examples and make sure that it works as
143
00:08:34,850 --> 00:08:35,510
expected.
144
00:08:35,720 --> 00:08:42,110
That's how you will grow and that's how you will learn more about yourself, about your skills and about
145
00:08:42,110 --> 00:08:46,790
how you tackled programs, problems in C programming language.
146
00:08:46,910 --> 00:08:48,860
So thank you so much for watching, guys.
147
00:08:48,950 --> 00:08:52,490
Keep on practicing and I'll see you in the next video.
12810
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.