 Hello everyone, I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. So today is day 19 of the C and C++ coding bootcamp. And in today's session, like in last session, day 18, I discussed about strengths in C programming. So in continuation with that, in this session also, we are going to discuss about strengths in C programming. So like I hope you understood the concepts and I demonstrated you few programs as well. So in today's session also, I will be first explaining few concepts and then we'll discuss a few examples, right? Before starting the session, if you want to know about me, so in this slide, everything is written, what I have done, what I'm doing, how many years of experience I have and what all certifications I have done. So you can go through and you can get to know me. And if you are learning programming and you are passionate about it, so you should be consistent enough. So consistency is a key, so please do regular practice. And if you want to discuss your doubts, so you can join this telegram group and you can ask any kind of question related to C and C++ in that group. And if you want to receive timely notifications, just follow Sanjay Gupta Tech School on YouTube, LinkedIn, Instagram and Telegram and all the important links are available in the video's description. Okay, so starting with strengths in C programming, right? So in yesterday's session, I discussed about the concepts and we discussed about some programs as well. So in today's session, I'm going to bring in front of you some predefined functions, those we can use with C programming. And for that, you basically need to use string.h header file, right? So here you can see we have a header file. So in all the functions, all the programs as of now, we use this stdio.h header file. But here to understand this concept, we need to include string.h header file as well. So I'm just clearing this code. So here we have five predefined function that I'm going to demo you one by one. And these are predefined function. Why it is called predefined because you don't need to write how it will be working. All the process of this function is already defined with string.h. So you just need to include header file and then you will be able to implement that particular function, right? So with the help of this predefined function, you will be able to solve a requirement. So here you can see we have a variety of functions available. So we have strlian, we are having strcpy, we are having strcat, strcmp, strrv. So first one is used to identify length of a string, how many number of characters are available in a string. So I'm going to show you how we can test it. So first of all, I'm going to create a string. So care str, so initial size is 20, then I'm taking variable n. So n will be having length of the string, right? Now here I'm going to just a second. Okay, so here what I'm going to do, I just declared two variables, one is of type character string and one is of type integer n. Now I'm going to write printf and here I'm going to receive a string. So enter a string. So you can enter any combination of alphabets, digits and spatial symbols. And to receive it, I'm using getus and passing str, right? So getus will be receiving the string from user as an input. Now here, what we are going to do, we need to use predefined function. So I'm using str alien and here I'm passing str. So what will happen, whatever number of characters will be available or you will be entering into str as input. So that string length will be counted and the result will be stored into n variable. So now here I'm going to write printf then length equals to percent d and then we can write n, okay? So initially we declared a couple of variables then we are going to receive input from user through printf and getus. Then this is predefined function, right? So here we have implemented predefined functions. So it basically counts length of the string, whatever number of characters are available in the string. So that will be counted and the result will be available into n variable and through this printf value of n will display on UI as output, right? So now I'm going to run this code so that we can test it out. So here we need to enter a string. So I'm entering my name Sanjay space Gupta and you can see length is 12. So it basically counted all the characters. So S, A, and J, A, Y, six, then it counted space as well as a character, then Gupta, so total 12. So alphabets are 11 and one is space. So that's why length is 12, okay? So I hope with this demonstration you are able to understand how actually it is working, right? So still if you have any doubt you can ask questions in the chat. I think it is straightforward and it is useful as well because it is predefined. You just need to use it for processing purpose and whatever code is required for this function you don't need to take care about that. It is already predefined. That's why it is called as predefined function. So similar to printf, scanf, getf, putf, we are using str alien. All these are predefined functions, okay? So next we have strcpy. So here basically if you have one string which is having some data and you want to copy that data into another string. So for that purpose basically you can implement strcpy, right? So strcpy basically copies one string data into another, right? So let's see how it works. So we need to create two strings. So str1, then str2, then we are reading values into str1. And now here I'm going to write that strcpy. So strcpy str2, str1. So what will happen? The data of str1 will copy into str2, right? And here with the help of printf we will be able to display the result. So string2 equals to %s. And here I'm writing str2. So we are going to display string that's why I'm using %s here. Then that string variable. So we are going to copy str1 into str2. So input will be stored in str1 and output we are displaying with the help of str2. So whatever we are going to input the same result should be available on output screen as result, right? If that happens, so it means strcpy is able to copy string1 into string2, right? So now what I'm going to do, I'm going to run this code. So here I'm entering sanjay and I just pressed enter, you can see. I entered sanjay and string2 is also showing sanjay. Okay, so this way what is happening? Data of str1 is getting copied into str2 and that str2 we are displaying with the help of printf, okay? So I hope this makes sense and you are able to understand this as well, okay? If you still have any problem, so you can just raise this concern, okay? So if anyone is facing any issue, please raise the concern so that I can help you out, right? So if you don't have any concern, so I hope you are able to understand. Now next is strcat. Strcat is for concatenation. Strcat is for concatenation. So for that we need to read data into both the strings. So here I'm writing enter for string, here I'm writing enter second string, right? So str2. So concatenation means the data of one string will be combined into another. So here what will happen? Data of str2 will be added into str1 at the end. That means concatenation, right? So str2, whatever data we'll be having, it will be added into str1, right? So the result will be available into str1. So string1 will show result of both str1 as well as str2, okay? So I just modified this code. Now I'm just going to run. So first string I'm entering sanjay. Second string I'm entering gupta. And here you can see string1 is showing sanjay gupta. So both the strings data is concatenated, right? So this is another predefined function that you can use. Next is strcmp which is for comparison. So it will compare the data of two strings. And if both the strings are equal, so this n will be receiving zero. So here you can write printf equal. And then you can say else printf unequal, right? And I'm removing this printf. So if you are trying to compare two strings and if both the strings data is equal, so the result will be stored into this variable n. And if n is double equals to zero, it means the comparison result is zero. It means string values are equal. If it is not equals to zero, it means string comparison result is basically unequal, right? So this way you can utilize the functionality of strcmp, okay? Now we just need to run the code and check whether strings are equal or not. So in first string I entered sanjay. In second I entered gupta. And you can see the result is showing as unequal. If I run it again and if I enter sanjay at both the times, so it is showing equal. So this way we can validate our code is working fine. Both the strings are able, like we are able to compare both the strings. And if comparison result is equals to zero, it means strings are equal. If comparison result is not equals to zero, it means strings are unequal, right? So this way we can use strcmp also. And last one is strrev, string reverse. So for this, I am just removing or maybe I am just commenting these statements. And here I'm writing strrev. So yeah, it is throwing error. So actually it is not processing strrev. So in this compiler, this string reverse function is not supported. So you can see here it is showing the warning. And here it is showing undefined reference to strrev. So basically it is not supporting it properly, but we have this reverse function, right? So I won't be able to demo this, okay? But you can search about string.h on internet. So string.h header file functions in C. So here you will see all the functions. So if I open this, so here you will find the library. So all these are the functions, right? These functions you can use. I think strrev is not available to use now, okay? So here in this list you can see function name and its explanation is available. So with this list you will be able to understand it, right? So I just explained you four examples. You can just ignore strrev, right? And other examples I showed you, you can just search the list and you can practice. So this was about predefined functions. Now let's discuss about some exercise or examples that I'm going to implement for you. So in this first one is read a string and check whether a particular character is available or not, right? So what we are going to do, we will be reading a string and we'll be checking whether a particular character is available or not, right? So in a string we need to check whether a particular character is available or not. So first of all, I'm going to read a string and here I am creating a variable found which is initially zero. And here I'm writing variable I, making it str, enter a string, then I'm removing all these unnecessary statements, okay? So after this we need to read a character as well. So I'm creating one more variable care ch. So we need to read a string, then we need to read a character that we want to search. So here I'm writing printf, enter the character you want to search, okay? So what is happening? First we are going to receive a string in which we want to apply searching and which character we want to search that we are going to receive into ch, okay? So it is quite straightforward and we have a variable found which is equals to zero. Now what we need to do, we just need to check whether ch, whatever data is available into ch, that data is available into str or not, okay? So now I'm going to apply a loop. So here you can see the loop condition if null is not like loop will process until null is occurred, right? So all the characters are processed and inside this for loop we can apply if condition if str of i w equals to ch. If string of i is w equals to ch, then it means your character found. So we can say found equals to one and we can break. So if this condition is true, then only found will be equals to one and this loop will terminate. If this condition is false, then loop will iterate, right? So maybe it may happen like sometimes you provide some data into a string and that character that you want to search is not available in the string. So in that case, this if condition won't be true anytime. So if it is false, then found equals to one won't process. So found will be equals to zero. Found equals to one will set if the ch is available in the string, right? So now what we need to do here, if found equals to one, it means we can say character is present in string, right? Otherwise what we can say, character is not present in the string. So this way you can apply searching and break keyword we already discussed. Break is used to terminate execution of the loop. So if anytime character is found, so we don't need to process the loop or string anymore. We can just break the loop here. And then we have this if else condition, so accordingly result will be displayed. So now we need to test it, whether it will work fine or not, so I'm entering Sanjay and the character I want to search is A and it is showing character is present in string. Now I'm going to run it again. Again I'm entering Sanjay and this time I'm going to search for B and B is not available, so it is showing character is not present in string. So in both the cases code is working fine, okay? So I hope with this explanation you are able to understand how we can implement a program where string is available and we want to search whether a particular character is available in the string or not, okay? But if you implement this code yourself then only you will be able to understand, right? So whatever I am demonstrating, you just need to implement those code by yourself as well. Now next is print ASCII values of each character of a string. So ASCII basically stands for American Standard Code for Information Interchange. So in programming for each character there is predefined ASCII value available, right? And ASCII values are available in form of numbers, digits. So for each character there are some digits associated. So through code we can identify for which character, which ASCII value is predefined. So now I'm going to show you that thing. So we are going to receive the string from user. I'm removing unnecessary variables. So we need a string variable, we need I for loop processing and here I'm going to write printf. So printf backslash n percent c equals to percent d and here I'm writing str of i comma str of i. Okay, you might be wondering what I did. So at line number 13 it is important. So I'm showing str of i twice. So str of i is indicating particular index. On that particular index there are some values available and both the times I'm using str of i but one time it will display with the help of percent c. So it means the character which is stored in that string will be displayed and next time the integer which is associated with that character that is actually ASCII value. So that ASCII value will be displayed in place of percent d. So if you want to display a character use percent c, if you want to display the ASCII value of same character then use percent d. So now I'm going to run this code and I'm entering Sanjay and you will see the result. So here you can see ASCII value of s is 115 a 97 and 110 z 106 a again 97 y 121. So this way whatever character we are going to enter ASCII values will be there. If I run it again and enter India. So again you will see different ASCII values but for that particular character it will be same. So in previous output a was having ASCII value as 97. So here also it is same for I it is 105. So I is available in twice in India. So that's why it is showing 105 twice right. So I hope this way you are able to understand how we can display ASCII values of particular character. Okay now next question is also dependent on ASCII values. So we need to count how many uppercase lowercase digits and spatial symbols are available in a string. So basically for uppercase we have ASCII range for lowercase we have ASCII range for digits for spatial symbols as well. So now let's implement it so that we can count. So C1 C2 C3 C4 right. So uppercase lowercase digit and spatial symbol. So for entities we need to count so I created four variables and here we will be applying the condition. So initially we need to read the string. So through printf getters we will be reading the string. Then in that string we need to count how many uppercase lowercase are available. So str of I is greater than equals to 65 and str of I less than equals to 90. So if this is the case so here the 65 and 90 is ASCII value. So for uppercase A capital A ASCII value is 65 for capital Z or Z it is 90 right. So if any character is having ASCII value equals to or greater than 65 or less than equals to 90 it means that character is basically uppercase later. So we can say C1 plus plus then else if we can say str of I greater than equals to 97 and str of I less than equals to 122. So here you can say C2 plus plus right. So this is the range for lowercase characters. So I'm writing comments as well. So this is for uppercase this range is for lowercase. Then comes digits so it is str of I 48 and 57. So C3 plus plus it is for digits and then else here C4 plus plus rest are spatial symbols. So you can see with the help of ASCII values we are able to segregate uppercase lowercase digits and spatial symbols right. So if you don't remember ASCII values so I showed you how you can display ASCII values as well. If still you don't remember you don't know the code so on Google you can search ASCII values so you will be having the range and accordingly you can use. Now after this complete loop we can have printf statement. So we can say uppercase count will be displayed with the help of C1 then we need to show lowercase then digit and then spatial symbols. And here C2, C3 and C4 right. So this way results will be displayed okay. So now I'm going to run this code and here I'm entering some uppercase, some lowercase digits spatial symbols and enter. So here you can see for each count is two because I entered two small letter, two uppercase letter, two digits and two spatial symbols. So the results are in front of you okay. So this way I hope you will also be able to implement this solution and here we are using loop, if else, combining we are using logical operator, relational operator. So whatever we have understood so far in all these sessions we are combining them in every example. Right, so next is we need to convert uppercase letter into lowercase and vice versa. Okay, so I am removing this, this as well. Now as we all know like how we can identify whether the input letter is uppercase or lowercase. So for uppercase this is the ASCII value and for lowercase it is 97 to 122. So what is the requirement we have? We need to convert uppercase into lowercase. So uppercase ASCII value is 65, lowercase ASCII value is 97 and the difference is 32. So what I'm going to do, I'm going to write str of i equals to str of i plus 32. So if I add 32 into 65 it will convert into 97 and it will again store at this position. So that uppercase will convert into lowercase. And if I copy and put else and the conditions. So if I check it for 97 and 122, so for uppercase ranges 65 to 90, right? So if you want to go from 97 to 65, so you need to subtract 32. And if it is the case for uppercase a to lowercase a or lowercase a to uppercase a, so it will go similarly for all other alphabets as well. So for capital B it is 66, for small b it is 98. So again difference is 32, right? So that's why it is generic code which will convert your uppercase into lowercase and lowercase into uppercase. So now I'm going to run this code so that you can see, but prior to that I'm going to show the result as well. So string will be modified and we are going to show that. So I'm just clicking on run. So here I'm entering sum in small and jay in uppercase and entering. So you can see the result. This s a n converted into uppercase and jay converted into lowercase. So this is the proof our code is working fine, okay? And why we applied these conditions because in your string there may be possibilities. We have digits and spatial symbols as well. So they will be ignored. Only uppercase and lowercase will be converted. So define proper conditions and then only you will be able to get proper results. Okay, so I hope with this demonstration you are able to understand everything about string. So there are two sessions, today's and yesterday's, go through both the sessions so that you can understand string properly. And follow this session tracker. Here you will see we have completed so far 19 sessions and these are the upcoming topics which are listed over here. So keep an eye on this session tracker because I'm timely updating it, right? And here in this session tracker you have exercise sheet link as well. So you can just click and follow that as well, okay? And I think this bootcamp will run two to three months long because we have lots of sessions remaining for C programming and then I will be starting C++ programming. And I think this bootcamp sessions will be helpful for the people who are from BTEC background. They started their journey and right now admissions are going on and whoever is watching this video or like if someone share with you like on Sanjay Gupta Tech School you will find videos related to C and C++ programming. So just follow this bootcamp and master your coding skills because in BTEC first year, second year these C and C++ programings are very important if you know and if you are from non-technical background still you want to jump into IT industry, you want to become tech expert. So for you also like at least you can try implementing some coding related stuff, right? So this is all about strings in C programming and if you have any problem you can just reach out to me through Telegram group and please share a review or feedback about the bootcamp. And Sumukh is asking, does C++ programming helps in Salesforce? Yeah, so in C++ we will be learning about object oriented concepts. So when you will be learning Apex programming after C++ so it will be more easy for you to understand the concepts of Apex programming, right? So with this I take your leave and the next sessions I will be having next week related to the C and C++ coding bootcamp. So stay tuned and do regular practice. Thank you so much guys, those who joined live and those who are watching recording thanks to you as well. Bye everyone.