 Hello, welcome to the session user function in C to compare given strings. At the end of this session the student will be able to write a C program to compare two given strings using their own function without using strCMP that is the library function. Now strCMP is a library function to compare two strings, first we will see what is the syntax or prototype. So, here syntax for strCMP is integer strCMP as it is a integer it is returning value integer value. So, it is a integer function and here it is giving a character pointer str1 and character pointer str2. So, these two strings are compared str1 and str2. So, one more thing in this case is strCMP function is case sensitive that is for example capital A and small a are treated different characters they are not considered as a same character. So, as I said strCMP function in C compares two given strings and returns 0 if they are same and if length of string 1 is less than string 2 then it will return the value which is less than 0. And if length of string 1 is greater than string 2 then it will return the value which is greater than 0. Now in this program we will see first using the library function, so in this program two strings will be compared and 0 will be written when strings are equal and negative value when first string is smaller and positive value when string first is greater than second. Now how it happens we will see in this using the library function this is str.h that is the standard then we are including str.h for using this strCMP library function. So in the integer main we are declaring first str1 as a fresh in the double core then second string str2 as a refresh. Now integer i, j, k it will give some different values as per our comparison i is equal to strCMP str1 it will be compared with the fresh in the j the value is indicating when str1 comparing with str2 that is fresh comparing with refresh and k that is comparing str1 to a single character f and then we will print i, j, k value. So in the first case i, i is comparing fresh with fresh so it is giving the value 0 in the second j str1 that is fresh is comparing with refresh so it is giving the value minus 1 and in the third case str1 is comparing with a single character f so our fresh is more characters than single f so it is a positive value. So this is the library function strCMP for the comparing two strings. Now without library function we have to write a program now what is the logic for this we will create a user function to compare two given string now we will scan one by one characters of same position in the source string array and target string source string means first string str1 to second string str2. Now if any character is not matching from source to target string then it will be returning 1 if matching it will return 0 if return value is 1 both strings are not matching and 0 value is there then the string is same in both array. Now in the memory position we will see that source string is there and distinction string is there source array s1 s2 s3 s4 like this it is shown and destination array d it is having d1 d2 and here I took the example of fresh in the source and fresh in the destination. So it should give the answer 0 that is both strings are matching so how that happens now first character in the string s and first character in the string d they will be compared to each other then it will go to the second position if they are matching it will go to the second position then they will check second position of s and second position of d if they are matching it will go to the next like this they are checking all the characters one by one to that particular same position of the destination and when they are getting null value they will stop the comparing both strings and both strings are matching as same array position the characters will be all matching so it is a same string we will see our own write up of the function that is for string comparison. Now in this case we are declared character string 1 and string 2 arrays of 1550 integer i temporary is equal to 0 here we will getting the first string with the help of get a string and then second string with the help of get a string 2 then you can see here for loop is there and string position will check one by one so if string one of first position of is equal to string of 2 of the same position means if it is having string 1 of 0 and string 2 of 0 both are same temporary is equal to 0 else it will be 1 like this and the for loop will complete for the total string and then if out of that for loop will compare check that temporary is equal to 0 then both strings are same if it is false then will print that both strings are not same so here we are taking one example that enter the string one value is fresh and enter the string two value is refresh so they are different string so it both strings will be not same now same we will compare the string without strcmp but here we are using the function so here main program is written that we have declared the character a and character b that is the array of character a and character b and then input a string for a with the get s then input a string with get sb compare both strings this will be our function a, b we are supplying a and b and then we are writing the result so the function will be called here so we are going to the function integer compare string which is here also declared and here called and here it is implemented or written integer compare string character a and character b that is the string a and string b so integer c it will be the counter or indexing while a of c is equal to equal to b of c and they are not reached up to the null character we will compare all this and once we are reaching to the null character it will be break up till that we will increment that c plus plus so if we are reaching to the null character it will be return 0 else it will be giving 1 so here both strings are welcome and welcome it will be equal string now check this program and then pause the video and write down the function to compare a string using pointers for given this main program here I have declared the function integer compare underscore string with the pointer two pointers source and destination or string one or string two then it is declared here we are taking both values here input a string get s first input a string get second then we'll write the result is equal to by calling the function compare underscore string and we are supplying first and second string which we are having to compare if result is equal to 0 they are same and else they are different so this is the solution for you this is a function written here integer compare string so first and second which we are getting from the main then while pointer content of that pointer first and content of that pointer second if both are equal that is the characters are equal and it is not a null up to null it will be run this while program and it will be incremented the pointer of first incremented pointer of second and once it is finished and we are reaching to the null value then it is going to return 0 if not then it is returning 1 so anywhere the comparison is not matching then it will become out and it is not giving the value of null and so it is returning minus value references thank you