Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,150 --> 00:00:05,850
All right, welcome back, ladies and gentlemen, and in this video, what we are going to do is we
2
00:00:05,850 --> 00:00:13,830
are going to implement all by ourselves the function that we all have been using and talking about,
3
00:00:14,130 --> 00:00:21,930
which is actually actually these function is a part of this string that each library and this function
4
00:00:21,930 --> 00:00:25,270
is none other than the RCP y.
5
00:00:25,560 --> 00:00:34,050
And as you can remember, that Evy's function, all it does is simply receives one, let's say, one
6
00:00:34,050 --> 00:00:40,430
place in memory where we are going to copy a string from another place in memory.
7
00:00:40,440 --> 00:00:46,890
So it was something like char pointer is the destination destination.
8
00:00:47,460 --> 00:00:56,120
And also it received a string location where we want to copy from.
9
00:00:56,140 --> 00:00:57,840
Okay, so it's the RCR.
10
00:00:58,410 --> 00:01:06,270
It's the source is actually the source string that we wanted to copy to as to our destination place
11
00:01:06,270 --> 00:01:07,050
in memory.
12
00:01:07,290 --> 00:01:14,040
And we've seen also how we can use it basically by including this string that H and how we can use these
13
00:01:14,040 --> 00:01:16,620
as the RCP y for our needs.
14
00:01:16,890 --> 00:01:23,070
And also we talked about what are the limitations of the RCP, why, how it should be used, when it
15
00:01:23,070 --> 00:01:29,000
should be used, and basically what we should kind of avoid while using it.
16
00:01:29,010 --> 00:01:34,740
And in this video, what we are going to do is that we are going to say, all right, we know that these
17
00:01:34,740 --> 00:01:37,740
string that H includes the SDR recipe Y.
18
00:01:37,980 --> 00:01:45,000
So what we are going to do is simply to delete it and think about, OK, we didn't have this library
19
00:01:45,000 --> 00:01:49,680
yet and what we want to do is to develop these function.
20
00:01:49,710 --> 00:01:56,250
OK, let's leave it this way is to develop these function all by ourselves, basically implementing
21
00:01:56,280 --> 00:01:59,250
these function in one way that it will work.
22
00:01:59,250 --> 00:02:00,180
Exactly.
23
00:02:00,180 --> 00:02:04,830
Or pretty much as it has been working in the string that age.
24
00:02:05,400 --> 00:02:11,460
And the reason for doing so is very simple because we want to improve our programming skills and we
25
00:02:11,460 --> 00:02:16,890
also want to learn how we can create functions that are similar to other functions.
26
00:02:17,080 --> 00:02:21,300
Of course, if you just need to like to run your program, that's OK.
27
00:02:21,570 --> 00:02:28,710
But a lot of times features and also interviewers, they will ask you, OK, so you're using these as
28
00:02:28,710 --> 00:02:30,030
the recipe y function.
29
00:02:30,030 --> 00:02:33,210
But do you can you can you tell me the logic behind it?
30
00:02:33,420 --> 00:02:42,900
Can you tell me why these function runs as it's, as you say, runs and in this place in time you have
31
00:02:42,900 --> 00:02:50,100
to start thinking about, oh, wait a second, what really is going on behind the scenes and what is
32
00:02:50,100 --> 00:02:52,010
really happening in this function?
33
00:02:52,410 --> 00:02:59,880
And one of the ways to do so is to practice, then to write the implementations kind of from scratch
34
00:02:59,880 --> 00:03:01,620
like we are doing right now.
35
00:03:01,860 --> 00:03:02,350
Awesome.
36
00:03:02,370 --> 00:03:03,740
So let's let's begin.
37
00:03:03,750 --> 00:03:09,990
And first of all, what I want us to do is to like, you know, like create our of our main function.
38
00:03:10,230 --> 00:03:16,620
And here we will use, I don't know, some strange let's make it my name.
39
00:03:16,640 --> 00:03:19,610
OK, so my name and we will use here.
40
00:03:19,800 --> 00:03:20,600
Let's use it now.
41
00:03:20,610 --> 00:03:23,070
Let's use my nickname, my nickname.
42
00:03:23,490 --> 00:03:26,970
OK, my nickname will use here or something like that.
43
00:03:26,970 --> 00:03:34,350
Alphatech OK, so we will use Alphatech as our input string is our source string and also we will create
44
00:03:34,350 --> 00:03:41,460
some destination's trend which will be like, like let's say a copy of nickname.
45
00:03:41,460 --> 00:03:43,200
OK, copy of McNee.
46
00:03:44,010 --> 00:03:49,650
Anything will be let's give it some size, I don't know, like 30 characters just to make sure that
47
00:03:49,770 --> 00:03:53,130
we have enough space to make this copy.
48
00:03:53,130 --> 00:03:53,700
All right.
49
00:03:54,000 --> 00:04:00,760
And now what do we want to do is to say that we will use the CPA function.
50
00:04:00,930 --> 00:04:03,230
One way to do so is the RCP y.
51
00:04:03,240 --> 00:04:11,830
OK, so for some reason it remembers previously that we have been using it, but we will use here of
52
00:04:11,890 --> 00:04:12,830
the destination.
53
00:04:12,870 --> 00:04:19,210
OK, so copy of nickname and also we will use here the source right at the source.
54
00:04:19,210 --> 00:04:20,530
So my nickname.
55
00:04:21,240 --> 00:04:25,230
So basically these function is not defined yet.
56
00:04:25,230 --> 00:04:26,460
It's not declared.
57
00:04:26,470 --> 00:04:28,020
Well we know nothing about.
58
00:04:28,020 --> 00:04:34,050
If we will try to build and run it, probably you will not be able to use it unless it is part of the
59
00:04:34,350 --> 00:04:35,160
Dileep.
60
00:04:35,160 --> 00:04:36,900
No, I don't think so.
61
00:04:36,900 --> 00:04:38,130
It was part of the string.
62
00:04:38,130 --> 00:04:44,990
That age probably only remembers the signature because I just removed the include string that H.
63
00:04:45,240 --> 00:04:49,920
So either way, what we are going to do is to write this function down.
64
00:04:50,190 --> 00:04:51,990
So let's start in.
65
00:04:51,990 --> 00:04:55,980
The first thing that we have to do is to first of all, right.
66
00:04:55,980 --> 00:04:59,730
Of a function signature and what should be the function signature.
67
00:05:00,290 --> 00:05:05,780
Basically, it also can be of every type, because we can see here that the function does not return
68
00:05:05,780 --> 00:05:12,200
anything, but also we may say that we would expect to use this function in kind of like, you know,
69
00:05:12,200 --> 00:05:17,080
like this wasso copy of nickname will be equal, like something like a starship.
70
00:05:17,090 --> 00:05:24,500
You why if this copy of a nickname was a pointer, a dynamically a dynamic pointer or something like
71
00:05:24,500 --> 00:05:24,730
that.
72
00:05:24,740 --> 00:05:33,050
So for example, if you had here or something like let's say temp result, temp result and inside of
73
00:05:33,050 --> 00:05:38,900
temp result, you would use it like that as a temp result equals to WDR, if you like, kind of to make
74
00:05:38,900 --> 00:05:49,580
sure that the RCP y also returns returns of the exact address of where the string was copied to.
75
00:05:49,990 --> 00:05:57,110
OK, so what we are going to do is to say, OK, if we want to make sure that the function returns,
76
00:05:57,110 --> 00:06:02,000
the address of the destination string of where it has been copied to.
77
00:06:02,010 --> 00:06:05,930
So what we are going to do is to write the type as a star.
78
00:06:05,930 --> 00:06:11,360
Right, because we want to return the address of the first character in the string.
79
00:06:11,780 --> 00:06:16,640
And we are going to say that the type are the name of the function will be as the RCP y.
80
00:06:16,680 --> 00:06:17,650
OK, awesome.
81
00:06:18,190 --> 00:06:24,370
Now we are going to use our star destination and our star source.
82
00:06:24,830 --> 00:06:25,850
OK, awesome.
83
00:06:26,270 --> 00:06:35,420
So what do we want to do now is that first of all, you can also make sure that there is enough memory
84
00:06:35,420 --> 00:06:42,440
in the destination and you can, I don't know, kind of run some loop to make sure that the destination
85
00:06:42,740 --> 00:06:47,690
addresses that you can access is actually more in memory than the source.
86
00:06:47,690 --> 00:06:50,900
Because you remember, the first rule that we spoke about is the RCP.
87
00:06:50,950 --> 00:06:52,830
Why is that the destination?
88
00:06:52,850 --> 00:06:59,900
It's kind of our duty as the developers to make sure that there is enough memory to copy to.
89
00:06:59,930 --> 00:07:00,260
Right.
90
00:07:00,260 --> 00:07:02,870
So the source is 10 bytes.
91
00:07:02,870 --> 00:07:06,520
So there will be at least 10 bytes at the destination.
92
00:07:06,950 --> 00:07:09,800
So you also make add these are check here.
93
00:07:10,400 --> 00:07:11,770
So that's also OK.
94
00:07:12,110 --> 00:07:20,630
And what I'm going to do is to like, let's say to create additional variable and this additional variable
95
00:07:20,630 --> 00:07:21,560
will point.
96
00:07:21,740 --> 00:07:22,340
All right.
97
00:07:22,340 --> 00:07:26,240
It will point to the address, the the first element of the destination.
98
00:07:26,240 --> 00:07:28,210
So let's call it temp.
99
00:07:28,220 --> 00:07:29,920
Let's call it temp BTR.
100
00:07:29,980 --> 00:07:39,720
OK, so Tempa and we will say that tempters will be pointing to the destination destination.
101
00:07:39,770 --> 00:07:40,290
Awesome.
102
00:07:40,790 --> 00:07:45,770
And now what we are going to do is that we know that the source is a string.
103
00:07:45,770 --> 00:07:46,090
Right?
104
00:07:46,100 --> 00:07:51,270
He's pointing to a string and we know that every string ends with a backslash zero.
105
00:07:51,650 --> 00:07:55,440
So what we are going to do is that we are going to run some loop.
106
00:07:55,460 --> 00:07:59,480
OK, so let's create additional variable that will help us with that.
107
00:07:59,480 --> 00:08:01,430
So ENTI equals to zero.
108
00:08:01,550 --> 00:08:01,990
OK.
109
00:08:02,540 --> 00:08:04,850
And we are going to run as following.
110
00:08:04,850 --> 00:08:08,280
So just to make it as much easier for you as it can be.
111
00:08:08,510 --> 00:08:13,830
So while saurus OK source at the index of AI.
112
00:08:14,000 --> 00:08:14,600
All right.
113
00:08:14,780 --> 00:08:20,720
While Source said the index of AI does not equal to does not equal to backslash zero.
114
00:08:20,750 --> 00:08:21,110
Right.
115
00:08:21,110 --> 00:08:23,840
Meaning we didn't get until we didn't get.
116
00:08:24,140 --> 00:08:32,070
Let's wait till we got to the end of the source string.
117
00:08:32,420 --> 00:08:41,840
OK, so until this happens then we can say that destination in the index I will be equals to source
118
00:08:42,200 --> 00:08:43,050
of the index.
119
00:08:43,070 --> 00:08:50,450
I simply copying bite by bite meaning character by character are from source to destination.
120
00:08:51,110 --> 00:08:55,240
And that's what we are going to do also is to increment I by one.
121
00:08:55,250 --> 00:08:55,910
So I.
122
00:08:55,910 --> 00:08:56,600
Plus plus.
123
00:08:57,110 --> 00:08:57,710
All right.
124
00:08:57,710 --> 00:08:58,750
So then either.
125
00:08:58,940 --> 00:08:59,510
There you go.
126
00:08:59,510 --> 00:09:00,680
You copied everything.
127
00:09:00,740 --> 00:09:03,410
OK, so everything from the source was copied.
128
00:09:03,410 --> 00:09:09,550
And also you could you could have make sure beforehand that something like that.
129
00:09:09,560 --> 00:09:17,570
OK, I will not write it as part of our program, but if it's are land of let's say saurus is greater
130
00:09:17,570 --> 00:09:25,190
than and find the length of the destination, if you can find it, then return or print some problem
131
00:09:25,190 --> 00:09:27,440
or something like that, that's also an option.
132
00:09:27,680 --> 00:09:29,090
But I will not add it here.
133
00:09:29,930 --> 00:09:35,600
Just just that you will know that there are additional conditions in some conditions that you may add
134
00:09:35,600 --> 00:09:40,580
to like, you know, like to extend the functionality of these given function.
135
00:09:40,910 --> 00:09:47,240
OK, and now what we are going to do is that we copied everything from the source, all the characters
136
00:09:47,240 --> 00:09:49,010
from the source to the destination.
137
00:09:49,280 --> 00:09:54,340
And one character that we did not copy is the backslash zero at the end.
138
00:09:54,350 --> 00:09:59,690
OK, so we we run this loop until we reach a backslash zero.
139
00:09:59,770 --> 00:10:05,860
So meaning this nation does not have as the last character of the Bixler zero, which is exactly what
140
00:10:05,860 --> 00:10:13,630
we do not want, we want the destination's to be like to be pounded with these backslidden zero at the
141
00:10:13,630 --> 00:10:21,700
end, that it will specify that all of the characters coming before it, they are part of the destination
142
00:10:21,700 --> 00:10:22,310
string.
143
00:10:22,630 --> 00:10:28,750
So what we are going to do is that we are going to write destination at the index of AI, OK, because
144
00:10:28,870 --> 00:10:36,280
we know that I was incremented here one after the other and I will be at the index where a source has
145
00:10:36,310 --> 00:10:37,960
the backslash zero now.
146
00:10:38,350 --> 00:10:44,530
So destination and the index of AI equals to backslash is zero awesome.
147
00:10:44,990 --> 00:10:51,280
And basically we are almost done at this step of a destination.
148
00:10:51,280 --> 00:11:01,600
Already have copied all it already has copied all the characters from source and now all that remains
149
00:11:01,600 --> 00:11:02,440
is simply too.
150
00:11:02,440 --> 00:11:09,670
Like if it was of a void type, if this was like void ECPA, then we basically were done with this function.
151
00:11:09,910 --> 00:11:13,720
But we know that each would also return the address of the destination.
152
00:11:13,750 --> 00:11:22,390
So what we are going to do is return, return Tambe BTR or basically there is actually no real reason
153
00:11:22,390 --> 00:11:23,790
to as a way to do so.
154
00:11:23,800 --> 00:11:25,960
It just wanted to show you how to separate them.
155
00:11:26,320 --> 00:11:33,730
Stampeder points to the address of the destination, so meaning you could have just also returned the
156
00:11:33,730 --> 00:11:34,500
destination.
157
00:11:34,810 --> 00:11:35,240
Right?
158
00:11:35,260 --> 00:11:37,090
There is no reason why not.
159
00:11:37,250 --> 00:11:38,560
At least I can see.
160
00:11:38,560 --> 00:11:40,340
I cannot see it right now.
161
00:11:41,290 --> 00:11:42,820
So there you go.
162
00:11:42,820 --> 00:11:44,820
You've implemented these function.
163
00:11:44,950 --> 00:11:55,210
And now what we are going to do is to print the results or print the let's say the new copy, the string
164
00:11:55,210 --> 00:11:59,950
A's and percentage s here backslash and at the end.
165
00:11:59,950 --> 00:12:04,540
And here, instead of the percentages, we are going to use temp result, for example.
166
00:12:04,610 --> 00:12:10,000
OK, so temp result and also we can use just to make sure that everything work is expected.
167
00:12:10,030 --> 00:12:11,200
Copy of nickname.
168
00:12:11,260 --> 00:12:18,250
OK, so then you copied string and then you copied string on basically both of them are simply pointing
169
00:12:18,250 --> 00:12:20,650
to the same address just by different names.
170
00:12:20,680 --> 00:12:23,530
OK, so let's try to build and run it.
171
00:12:23,960 --> 00:12:27,850
So you go here, build and run and there you go.
172
00:12:27,850 --> 00:12:33,880
You can see that the new copied string is Alphatech and the new copied string is also Alphatech.
173
00:12:34,210 --> 00:12:41,470
And basically, I think, guys, that you're starting at this point to feel like you're more practiced.
174
00:12:41,710 --> 00:12:45,580
Basically, you implement you have implemented your own way.
175
00:12:45,580 --> 00:12:46,350
The the yes.
176
00:12:46,390 --> 00:12:53,110
The RCP y function that has been used by the string library string that h that we've seen in one of
177
00:12:53,110 --> 00:12:57,390
our previous videos and was developed by somebody else.
178
00:12:57,430 --> 00:13:02,720
Actually, I think OK, as a matter of fact, that you should be proud of yourself.
179
00:13:03,160 --> 00:13:04,710
So thank you guys for watching.
180
00:13:04,810 --> 00:13:10,450
Keep on practicing, write some notes down, try to write this function on your own, on your free time,
181
00:13:10,780 --> 00:13:18,820
and let's proceed with more exercises and more knowledge and becoming better programmers until next
182
00:13:18,820 --> 00:13:19,210
time.
183
00:13:19,210 --> 00:13:20,020
I'll see you there.
17768
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.