Hi everyone.
So in this video we are going to on some inbuilt functions of.
But Eddie So the first function that we will look to to start to use the land function.
So if you remember we have already implemented our own land function but this is already present in
C++ so the name of the function is string land.
This function is inverted.
So what this tingling function will take it will take.
String name as input order against it.
Correct Barry.
The name with the correct bit at is input.
So if you would read like this.
So let us create.
So this is character I'm creating a character input.
Eddie let's say the size is HUNDRED AND IF YOU WERE dig the input now you will call this function string
land.
So how do we call this function.
So let us with the answer inevitable.
I wouldn't call the function string linked and I will give input as parameter and then you can print
the land very simple.
So let us write the code but one thing.
So before writing the code this string length function is actually implemented in our head to file and
the name of the head the file is C string.
So if you want to use this function you have to include this defined.
So let's write the code no
so all the functions that we are going to discuss in this video I'd actually present in C string had
to fight so C string.
Now let us create our first arrays so string when little size is entered.
I will take input from they use it string one and let us call the function so I will the answer inevitable
lent the name of the function is SDR LDA in SDR alien string land and I will give a string one as input.
And now let us try to bring Deland so let's run our program
so net to the string is hello and you can see the output is 5.
So let us also print land here.
So
now again let's turn our program and let's say this time my input is ABC.
So the land is full and we have to it in the quarter for the land function.
So how this in built land function will work.
So this and world function will do the exact same thing that we were doing for example if your string
is a b c d and obviously a little present.
So this string then function it will just do the same thing as we did in our function.
It will start from me then B then C then D and medical regional it will stop and it will write down
the land which is full.
So exactly the same code that we have written in order to see these second inbuilt function.
So the second invalid function it this used to compare two strings.
So given two strings and you have to check whether the two strings are equal on article.
So the inbuilt function the need of the inbuilt function is string compared SDR C MP string compare
and it will take two strings as input.
Obviously it has two big two strings to compare it.
So it will take string one and it will take a strings to string two.
Now it will not return a boolean value.
Basically it will return a zero or a non-zero value and zero non-zero.
So if it is returning zero so that means the might do strings are equal.
And if it isn't attending a non zero value.
So this is non-zero so it will return do things that it will return a zero value or a non-zero value
if it is returning 0.
That means my two strings are equal and if it is returning non-zero value that means that two strings
are not equal simple.
So let us write the code and let's see let's see in action to test coming down these two lines
so create an idea at a string to size is rendered and let us take both the strings and put so string
wants to do so I will call the function string compared I will give first string I will pass second
string so if this function is returning visible net means that those things are equal.
So if the two strings that equal I can print equal
in the old part I can print an article
and now we will run our program there does desktop program
so let's say the first string is hello and second string is also Hello.
So both those things are equal.
So that's why equal is getting printed.
I just tested one more time.
So the first a string is ABC.
And the second string is ABC.
So they are not equal.
ABC and they really are not equal.
So let's test it one more time.
So first string is ABC second string is ACB.
Again these two things are not equal.
So that's why the output is coming out do we not equal so how does that string compare function will
work.
Let us try to learn.
So this stink compared function actually takes boosting that input so what it will do so let's say this
is my string when and this is my string to so let's say my string when is ABC and obviously then and
the second string is ABC and obviously nil.
So in this case in this case the board the strings are equal.
So my output will be equal and it will have done zero.
Let's see how we're doing.
Let's see how it will be done zero.
So what it will do it will reduce a practice or so protect it from me.
So a minus a.
So these are correct.
So and we know whenever you are doing character minus character.
So this is nothing but in Deja minus Deja.
So that character available will be converted to it.
Ask.
And so basically I am doing ninety seven minus nine defendants output will be zero.
Then we will compare.
We will have practice these two characters.
So B minus B again zero and then the total character.
So basically C minus C again zero so we are getting zeros at all the time.
So that's why this function will return zero.
And if this is it are done in zero that means all the characters are equal in the given string.
Perfect.
Now let us consider a case of non zero not equal so let's say my first string string 1 is actually ABC
and string 2 is actually ACB.
Now these two things are not equal.
So let's see what our function will return what I was doing some bear function will return.
So subtract a minus C so e might NSA 90000 minus 97 0.
Then subtract B from C so B minus C.
Now what does this.
This is ninety eight and this is ninety nine so you will get minus one.
So as soon as you get the value which is different from zero basically as soon as you get a non-zero
value then dusting combat function will are done that value.
So in this case stink compare function will return minus 1 and if it isn't attending a non-zero value
that means these two strings the given two strings are not equal so that is the working off string compare
function now can you implement string compare function yourself.
Yes definitely we can.
What we have to do is 1.0 at this position take one at this position compared both of them and move
ahead as soon as that if you encounter.
If you find out that the elements are different you will stop.
So basically I am writing the pseudo code for you.
You can definitely coded for yourself but you can do so.
Let us take a variable i equals zero.
So I am taking a variable life for same.
So basically first you can check what you can do.
So let me implement these things combined function for yourself.
So I am implementing string combat function for you so that they will be the C V.
We are implementing the function to
there's sure to be a K so I am implementing a string compare function differently.
So might might return David rebellion but there are two strings that equal or not.
And let's say string compared on.
So this is OK so let's name it.
My and compare my string compare what it will take it will take boosting Z input.
So this is String String 1 and the second string will be
string 2 but you have to do you have to just do data and check whether they are equal or not.
So first of all let us find our dear land so if what is the function of finding the land is the alien.
So if their lands are different.
If string my land is not close to the land of
if their lands are different that means they are not equal.
So you can detect leader down faults from here correct.
Now what you have to do you have to compare each and every correct.
So if we're comparing each and every character I just need to iterate.
So there are two ways of hydrating first.
You can write like this.
I's listing SDR alien of string when
and a listless so compared the I yet corrected.
So if the I yet get a bit of string when is not equal to the I yet corrected often string to so you
can read unfolds and finally you can pretend to connect.
So this is the first to be rating.
So let us check our program so I will call the function
so let's let's combine this.
Let's copy this.
So this is my string compared.
I will pass two strings string when answering do so.
This milestone can sting combat function is going to call this function and then type is a billion.
So let us test our program so the first string is hello.
Second string is also hello and the output is in the article.
Let us tested one more time for nautical keys.
So if my first string is left to ABC and sorry this is BSE and the second string is b c so they are
nautical
and the second off dating basically instead of using string meant function we seen the last radio we
can use and that is correct.
So what can I do I can write like this.
So this is basically a string when string of a So this is string when I get corrected is not equal to
Dean native character
so there are two ways of treating.
So this one and the previous one.
So let's test this one also
first thing is hello.
Second string is also Hello.
They are equal now the first string is let's say a b c d and second string is e only so they are not
equal.
So what I'm doing in this function.
So first of all I am digging through strings of input then I am finding out their length.
So if there lends an article definitely David in order to be close so I can then likely false from it
that I use for today and I do so.
One thing is very clear at this point both the strings have the same blend.
So the first testing is a BCG and the second string is ABC.
If then what will happen.
Yeah.
I will start from zero.
So this is I and I will move in this direction.
Simple.
You are competing guy you are trusting one with the iconic posting to compete everyday they adequately
move ahead to compare B to be dead equal move where to compare C would see that equal move ahead.
Now compare David F so they are not equal.
So as soon as they are not equal you will it unfolds and suppose if this is D.
So what will happen this condition will become false and all just all decided equal so you will return.
So that's how this is working and there are two ways of doing things so the first one the previous one
was very simple just like we used to doing at a equals you do a list and end it a plus plus and what
is n and is actually these string lent off string when you can write string two because they have the
same blend.
So this was the previous one code that we have written and the second one is using the null corrector
approach.
So there are two ways of writing you can choose anyone.
Now one thing that I want to clear here is basically that I am returning bool but the actual string
compare function.
I told you so it will return a zero value or a non-zero value so it's working is different and I hope
you can definitely implement the code for the inbuilt string combat function for yourself it is going
to be very very easy.
You just have to return.
So instead of boolean what you will do you just will change the return type.
So instead of returning false you cannot write this statement because you have to do DNA in digital
value so let's make it bool here.
So consider it as an exercise try to write the code for the inbuilt string compare function.
So now let us see the third and build function so we have seen lend function we have seen compared boosting
function.
Now the third function is actually copy string function.
So this is also in function but we have to do we have to copy one string into another string so the
name of the function is actually string copy.
So this is string S.B. VI SDR sleepy VI string copy function.
It will take boosting as input.
So first one is the destination string and the second one is actually solves the string and what is
the difference.
So what will happen.
So the content of the source of string would get copied into my destination string for example.
This is the first listing hello and this is your second string.
So in order to copy the content of a and b you can use this functions don't copy.
So you will write like this string copy copy the content of a in dooby simple copy the content of a
and b for example.
This is you listing A's.
Let's say this is correct Betty.
So this is easier and better.
And the string is ABC B's or so bad and the string is the E F.
So if you wouldn't call the function string copy if you look right back on my e or if you write a comma
B then what will happen.
The content of B will get copied inside.
So the B content of being will get copied.
So instead of ABC it will become the F and if you were trying to print the value of a.
So the value of A's actually the F no do not take my words.
So let us best have a called so we need two strings and let us initialize those two things.
So the first string instead of taking input.
Let us give the value here on the.
So the first thing is a basically
and the second string is actually that's called the F first is ABC.
The second is the F so I am not taking in anymore.
And so this is this comment.
This also.
So what do we wanted.
So I want to call the function string copy.
So first let us Sprint devalue before copy and we will print devalue after copying.
So before.
So what are the values we photocopying see out string when and let us also print string to
so I am printing string witnessing to be photocopy and we will also print after a copy.
So this is after a copy and here I will call the function string copying.
So SDR S.B. VI string copying first.
So what I want to do I want to copy the content of string to interesting one.
So first you have to write the destination string then.
Okay.
So I want to copy the content of string two into one.
So this is string to copy the content of string to and string one.
So let's see.
So this is before copy the content of a string when is ABC.
Now see after copying the content of string when changed to the F and the content of string to remains
the same.
Obviously the content of string will remain same because we are copying the content of string to undo
string one.
So string one was initially ABC.
Now it is the F.
So now let's try to understand how the in built a string copy function books.
So basically what I did here so my first instinct was so my string one it was actually ABC and what
was a string two.
So this was the F then I'm copying the content of a string to do string one.
So what will happen.
So the E F will get copied.
So the e f or the E F will come here and also so there is no character here also and here also.
So what this string copy function will do.
It will copy the null character also.
So instead of the instead of the usual right null so that's why.
What is the content of string when now.
So it is containing the E F then then and then.
So then you will call the function c out it alone LeBron.
D take it because it will encounter no light at this point.
So one thing to remember that string copy function so this listing can be function.
Also copy none so it will also copy detailed character.
This one character.
Okay so this is important thing to remember for distinct copy function so if I will write like this
string copy letters string 1 and I want to copy.
Hello.
So I can also do this.
What will happen.
Hello will get copied and do string 1.
So let's see so instead of string 2 you can write Hello.
So you can give a string here also.
So now let us start program
so you can see string 1 was initially ABC.
Now it is hello.
And obviously I didn't do anything with strings do so string two is remaining same.
Now how it is working.
So basically again the string copy function.
What it will do.
So first of all it will copy the content of Halo so string 1 was actually DCF.
So it is string when was actually containing ABC.
And then so it will happen.
Halo will get copied and also the note is.
So here do it.
What will happen so remove this one etch e n and all and this string complete string copy function it
will put the null connector by itself.
So this is not correct that will get automatically inserted will automatically appended by the string
copy function.
So the question is can you implement string copy function yourself so can you implement string copy
function yourself.
I am giving you the idea and take it as a homework.
You can definitely implemented for example.
So let's take one example and I will give you the idea.
For example this is string 1.
So what is string when ABC and what is a string to let's call it D.
If so what you will do you will take one point here and you will just I don't know what this string
so you will do something like this.
What is string so it is distinguished so string when I get corrected it is nothing it is just equal
to string to I get corrected.
So I am trying to copy the content of string to interesting Gwen so you will just irate over the string
too and you will copy the content.
So just remember you have to also copy the null corrected so they will get copied.
Then even get copied.
Then F will get copied and then corrected will get copied.
Simple very simple.
So your for loop what it will look like this.
You are trying to hide data with a string too so you will write like this equals zero i.e. less than
I did close to N and I bless bless.
So remember that inbuilt string copy function it copy the note corrected also.
So you have to copy the null connector that's way less than articles 2.
So what is n and this string lint off string to so you can definitely implement this code by yourself.
I am living this task to you.
So we have seen t functions till now.
So first one was the Lent function.
Second is compared to string function and the third one is actually copy strings hosting copy function.
Now let's see the fourth function so the fourth function is string and copy.
You want to copy the first and correct us.
So this is basically you want to copy these first and corrected off one string and do another string
so copy first and correct us.
So in the above function so what.
String copy will do string copy it will take to string string when answering to and it will copy the
whole string to undo string one and string do will not be affected.
So this this string copy function it copied the whole string but string and copy will copy only the
first and correct both.
So this is not copy this is the character.
So it will only copy these first and characters simple.
So for example my string Len is okay.
So what do we this index.
So you will write like this string and copy you will give the destination string then you will give
the source string and then you will give how many characters you want to copy first and correct this
will get copied.
For example if a string one is a b c d e and let us handle and what is your string to so the string
to is let's say hello and then obviously then.
So what will happen if I call the function string and copy.
I will give a string when I will give string to and let's say I want to copy first three characters.
So h e l will get copied so we remove these t characters and h e l will come here.
Now one thing to notice here is string and copy it will not copy the initial character so it will not
copy null character.
So no character is not going to be copied whereas string copy function it will copy these null character
so it copies Dean and characters.
So that is the basic basic difference between string copy and string and copy.
Again do not take my words we will write the code so let's make it.
Hello and instead of a strict copy function so I will call the function string and copy C.P. VI.
This is a string when then string do.
And I want to copy first three characters so let's see
so my string when was initially a b c d and string two was yellow.
Now after copying string one becomes edgy early and distinct to his Hello.
So why actually.
So it is very obvious so string one was ABC.
So this was the initial condition.
Then you are copying the first three characters of string two.
So what are the first three characters h e and so h e n so h e l so let's say the string one will become
edgy in and then the.
And obviously you have the character.
So again the string and copy function it will not copy the name but simple.
Now one note that you might be having in your mind is basically let's say if my first string is basically
so for example if my first string is actually a b c d and let's say my second string is actually x ray
only and if I call the function this one string and copy if I'm calling the function string and copy.
So copy the content of string to interesting one and copy these first four characters but if you will
see string to only has to correct those.
So what will happen.
Again it is very obvious again.
So first two characters will get copied.
So X will come in and virally come here but see we have to copy the four character first for character
and obviously we have only two characters so what will happen at least two characters will become null.
So the first two characters will get corporate X Y and the next two characters will automatically will
be copied the next two characters that will get copied will be null.
So instead of CMB MacLennan socially tried to print a string when the output will be excellent.
So let's see
so instead of yellow let's make it X X1 and as discussed the output will be.
So I want to copy the first four characters and the string two is containing only two characters.
So first two connect doesn't get copied X Y and the next two characters that are going to be get copied
and actually then corrected.
So you can see string one is X way.
Initially it was ABC.
So that's how it will work.
So now let's see the lost function.
So we have done Ford and function and are titles.
So the first function was SDR alien.
The second function was I think string compare and so SDL RCMP the third function was string copy as
DCP VI and therefore its function was string and copy and now let us see the last function.
So this is very simple string concatenate so string concatenate function but it will lose so this string
concatenate function it will be boosting as input.
So this is string one and this is string to so it will concatenate the content of a string to after
string one.
So for example if my string one is let's say ABC and if my string too is let's say the F and if you
call this function string concatenate so string two will get appended after string 1.
So basically leave it to the situation.
So a string one will become C D E F so B if we get copied at the end and string two will remain same.
Obviously we are not doing anything with string two.
So obviously do not take my word I will just write the code and we will see it ourself
so let's not use this function anymore.
Okay.
So what I want to do string concatenate so before concatenate so you NCT.
So before one congregation and after concatenation and let us call the function string concatenate I
will pass string one and I will pass this thing too to so copy the content of so concatenate the content
of string to after the string when simple.
So let's do let's run our program
so you can see string do is remaining same.
No changes.
But initially the string one was a b c d.
Now it is ABC.
Excellent.
So this is a b c d x y because a string 2 is now concatenated at the end of distinguished string to
is appended at the end of string 1.
So can you implement this string concatenated function yourself.
Yes definitely we can merge.
Do you have to do you just have to do basic basic thing.
So for example this is your string when you would lose all the ABC and then you have none.
And what is string to string do is actually the F and then you have nil.
So what do we do.
You will come at this point.
So what is this point so you can take a variable let's quality.
So what is I.
I use nothing but string land.
You can call the functions to England.
You will pass a string when so will likely come at this point.
So after coming at this point what do you will do.
You will copy discontent dual irate with this eddy and you will copy the content so for example you
will write like this string.
When let's call it.
So what I will do I will create a listing too.
So let's call it i.e. basically.
And let's call it.
And so this is.
And so what I will do I would write like this.
String 1 8 plus n is it close to string to 8 character and obviously you add I.
You have to copy that also.
Okay so it will become D then E then F and then you will copy dissonant so I equals zero I less denied
equals to so let's.
What is the length of this string.
So let's store it in a variable M so you will write like this.
String length of string do you have to copy the nettle correctly also.
So you can write like this.
This is m.
This is him and you will do a plus plus.
And that's on so I think this code should work fine how it will work because you can see what they are
doing.
You are trading on instinct too and you have to copy the entire content of string 2 so I equals zero.
I left an article stream I plus plus.
So we will take this for variables and to consider it for characters into consideration.
D E F and then and here what I am doing for string when so I am doing a plus and so I if the value of
FY 0 you are doing I listen.
So if you will if you will add plus 1 you will reach here.
So B will get copied in place often and so that's how it will work.
Or D will come here even come here and F will come here okay.
So I think this goal should work.
So what do you have to do.
You have to implement all these five functions yourself so just write the implementation of all the
five functions and from my experience I can tell you which functions are most important.
This one only this one and you can very easily implement this function.
We have also implemented this one string copy yes.
This is also sometimes useful but mostly I use only these two functions string length and string copy.
These two functions are very rarely used.
And similarly this one also.
So this one and this one are the most important.
So we have already implemented this one and we have also implemented this one.
I think you can implement the rest.
Three of them so this will be a very good according exercise for you.
I hope you guys can definitely do it.
So we'll see in the next one.
Bye bye.