 Hello friends, I am Sanjay Gupta. Welcome back on Sanjay Gupta Tech School. अब दिखने सी लेंविस वीडियो सीरीज और इस वीडियो में जो तोपिक मैं अपको इस्प्लें करने अगो वो है श्ट्रिंग. So this is lecture number 18. And in the last video lecture, I told you about 2D area and 3D area. So if you have watched that video, then you will understand this video properly. So before reading the link, you should know about 1D area, 2D area and 3D area. And at least you should know about 1D area. So those of you who haven't seen that video yet, then in the description of this video, there is a playlist link available. Through it, you can reach to that video. And in the playlist link, you can follow all the videos properly. So in this video, we will understand how this string works. And then as you can see that there are some programs here, I will tell you by implementing them. So in every video, we cover the theoretical part. Then we will implement it through the program so that we can understand things properly. So I have tried to do this in every video. And a particular topic related to playlists like 1D area, 2D area, string or other topics which I have made separate playlists. Only programs, programs of K video are available in that playlist. So I am providing that playlist in the description of every video. So when you go to the description of the videos, you will get a lot of details available. And these are my details. After watching the video, you will get a lot of doubts. Or you want me to personally take 1 to 1 classes so that I can clear my doubts. So you can contact me for that. So now let's start the string. So first of all, we will understand what the string basically is. Let's see some theoretical description. Then I will tell you the difference between the area and the string. And then we will talk about the programs. So if you read the first point carefully, the first point is that a string is a collection of more than one character terminated by a null character. So characters here means that you use alphabets, digits and spatial symbols. These are the three things that I told you in my first video. When you want to read C, you should know three things. We can use alphabets, digits and spatial symbols. And these are the characters. And if you want to store the collection of these three, you will use string. Then in this, it is said that terminated by a null character. So to represent a null, you have to use this. In single quotes, there is a backslash of 0. Null's ask value is 0. You have to always keep this in mind. Then string constants are always used in double quotes. So if a string is used as a constant, it will be used in double quotes. And we can also make a string type variable. For that, we will use care as a data. I will tell you in the next example. Then the last point is string can contain alphabets, digits and spatial symbols. Because all these entities are known as characters. Which I explained in the beginning. So basically, whenever you use string, you have to keep in mind that you can use the combination of alphabets, digits and spatial symbols. And in string, there will be more than one character. So to store it, we will use array notation. So if you will take a look at this slide carefully. In this, you will get the declaration of one d array. So I told you in one d array that we can make any type of array. So we use one d array as a string. So here you have to keep in mind that in the case of string, the data type will always be care. The name of the string can be anything. And the size can be anything. So the example is given below. Data type is care. Name is str and size is 10. Now note, if size of string is 10, then it can only contain 9 characters. Because null also occupies 1 byte. So you have to keep in mind that in string, null also has 1 byte result. According to the size. You have to provide total size string. So this is basically memory allocation. Which is similar to one d array. Total is 10 size, so 10 blocks. Every block has an index. So whenever you want to access a location, then you can use the index with the name of the array. So I will not explain this in detail. Because you already have to access the index in one d array. So when we implement programs, then I will revise it a little. So keep in mind that we have to use a particular index with the name of the array. And for repetition, we use the loop variable i. So that we don't have to write the index again and again. Below is a note. Each character occupies 1 byte of memory. So above string occupies 10 bytes of memory. So the character array we have declared here, which we will use as a string, total memory allocation will be 10 bytes. So I hope that you have understood this. And this is the initialization of the string. So you can write it in 3 ways. If you have written S1 and 5, then put 5 characters in it. There is no null in it. So if you do not store null, then this string will not be made. So you will call it character array only. If you have stored a, b, c, d, 4 characters and after that you have stored null on the fifth position, then this becomes string. And third form is there. What have we done in the third form? We have stored 4 characters. And on the fifth position, null will come on its own. Because what we are using here is double quotes. So when you put characters in double quotes, then null is stored on its own. And if you put each character in single quotes, then null will have to explicitly put you. So the second or third notation represents the string. Whereas the first notation is only character array. So you always have to use the second or third notation itself. And below is also written about it. S1 is array of character because null is missing. S2 is string because it contains null at the end. Then S3 is using double quotes and here null is inserted automatically. So it is also a string. So you have to use the third or second notation if you want to implement the string properly. Now reading of string. So to read the string, you can use the scanner or you can use the getters. So you must have seen that when we used 1D array, then in 1D array we used loop. In 1D array we use loop to read the integers or floats. So in the case of string, you don't have to use loop. So why is it like this? I will tell you practically. And you are also thinking that what is this null basically. I will tell you in more detail. So this theoretical explanation has two more slides. After that we will go to our compiler where I will tell you two things. 1D array which is an integer or float type and string which is a character type. The difference between them is that when we use loop there for reading and printing, we won't use loop here. So why is it like this? And the second difference I will tell you is that in 1D array we don't use null which belongs to int and float. Whereas in 1D array which belongs to string, we don't use null. So after these slides we will focus on it and then we will go ahead. So if you want to use scanf, you will use %s and string name. This statement reads sequence of characters from console until user presses space or enter key. So this space and enter will have terminators on both. So this statement automatically inserts null character at the end of string. So after this string, null character automatically inserts. So this first statement has scanf which you can read through the string. So always keep in mind if you don't want to read spaces you just want to read alphabets, digits or spatial symbols without any space, then you will prefer scanf. And if you want to read spaces including space string, then you will prefer get us. So this statement reads sequence of characters from console until user presses on the enter key. So this statement will also insert null character. So null will insert itself because here is %s and here is get us. So these two strings belong. So you just have to type characters and null will store itself. So let's talk about printing of string. So printf with %s and press enter. So you just have to type characters and then you have to insert the string. ओस उप्सिन्टे पूर स्यंट्टेस यूस गुस करो नल तक ज़ए भी खेरेकतरने सब ख्रिंटूजाएंलिए यसर ता पूर्टेस यूस करो यसर ता पूर्टेस यूस खुल्पियास यूस कर एक तब ता योंगस यहां पर्सेंट चीके तुई केके करेक्टर को प्रेंट करेगा और लूप हमने कहाते चलाया, जब टक की अपना जो अंडेक्स है वो प्रिदिस पोजिष्ट़प नहीं पूँँचाता, नल पर अपनोजन क्या निकलागी, नमपर को हमें लगलत लग लीड करना होता है, ये जो नमपर हैं, पाच नमपर हैं, खवर में कितने इंपृ चहीं हैं, पाच तो इस कोई अमपल्स्कनेद कितने बार लिपनीट होगा, पाछ ताइमस तो इसले जब भी यंटीजर अडेगो प्रो नेम या अपका खुदका नेम किस तरीके से इंपृ करावोगे, हर करेक्टर के बाद एक अंटर की, ता अब बोलेंगे नहीं, मैं इंपृ करावोगे अईसे, इंटिया एक बार लिखाओ और एक यी बार अंटर, तो ये कितने इंपृ हैं, एक और उपर जो लिख है वो कि या या, तो उपर प्श़ूए शोग कर बागता है, तो आब आप को इप दिख़न समझ आगगा होगा की, इंटिया के के यहा तो मुजे ये लूप लिटना बड़गा, for i equals to 0, i less than 5, i plus plus. ये ये किंटीजर का लूप हो गया, जिस में, scan f, percent d, m percent, k of i. जब की अगर मैं, श्टिंग की बात करूँँँँँँँँँँँँ, जब ना, ना, भाही, ऐ ऴ� क्य थिस श्टिया, क्यनाफ, k of morning, seconds, s t r. दोनो कि वो लुप योग limb Mystery स�姐 लगे रहा है �見े थे के दितने क्जाएक्योगे जैसाय खालगेर, तो, वो और गर खालतारYY उ inverse the list as you have थो अब आपका थिजया आपक मैं है, Laut Ontario U possible list and by some, अप आप बात करते है, नल की नल करेक्तर की रिगवायमें क्या है, तो आप फिरसे हम एक बार इनी को डिफ्रेंशीट कर लेते है, देखो यहापर इंटीजर आरे है, जिसका साईस फाइइफ, दूप कितनी भर चला पाच पाच पाच, तो पाच पाच अंपुट करना जिए � आप आप अप आप रऻ अप आप सकन अप जोगा थाद्ची मैंत्टीए करे को पीकडना जिए जोगाप्टादी eyeballs की आप जोगाप्टादीट ञ ہیں, वैंटाची जो वैगको जोगा पाच सब है, औगाप पाच पाच है, ज़े खरठस मेंजा फोड़ी दरन और सब भी है, कि अगर मैंने अपना नाम अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपने अपन a, y, jikkar, these 6 characters are stored now on this position, it can be stored by itself so whenever i will say that nul and string end is stored, so string end is on this index so it will be stored by itself on the index on its just back and these blocks are unused now it can be there is 3 characters in someone's name यसे के नेम में 3 करेक्टेरे से राम स्टोर करना है, तो राम तीन लोकेशन पर स्टोर जाएगा, तो नल कहांपे आजाएगा, तो बाखिया नियुज गयजाएगी। तो अब हमें कैसे पता चलिगा की कितना इंफुत आया, तो हम किसको सरच करेंगे नल को, जहां नल मिला वहांपे स्ट्रिंग तरमिलेतो, तो ये तोड़ा सा देख्रेंस है, यंटीजर और करेक्टेर आरे में, यंटीजर में तो जितना आरे का साईज होता था, उतना ही इंटुट कराते थे और उतने गो यी प्रोससस कर नावकाता, जब की स्ट्रिंग में क्या और आया, साईज कोछ होर आया, इंटुट कोछ होर आया आया, और हमें नल के तो उसको अईटिटिटगाए का. तो आपको इजी समच में आगे हो गी की यंटीजर में लूप चलता है, करेक्तर मैं नहीं श्ट्रिंग में लूप नहीं चलाना, और वहां यंटीजर अद फलोट में नल विखवायत नहीं है, कुछ जितना साईज है, उतना आईपुत है, टीता, अपी जरनज़म लिग पर टीवागे लाई, नहीं, अपी तेगले आप तहीए आप हो ठीग ना, इस गगी दोगाता, नहीं अप कुगे लिजासे लेग तют है गगे लिग वो आप लाई एक आउप भी औरक्मा के अप आप खान और गलना, ये रोगा को आप जगाखन उस्फ़गटिए मैं अप को अब आप ख़ेःट ढ़ेग किया रब और थखटिए समच में आब लोग आप वप यहागे उसेढा कर अब बच्याद अब इसको तो एड़ेस करते हैं और इस में आपको दोनो गेटेस अर शकनाप का भी देपरेस बतादूँगा तो ये मैंने देखलेर किया एक खेरेक्तर आरे जिसका साईजे 20 ल विर्येबल येलीन विर्येबल जिसकी वेल्यो आई विर्येबल अब मैं आ लिक रों, प्रींत प् selfie,श्लेषं, अभ्छ़र मणच्झ्प आूँँँँँँँँँ खुत्री this is the reading process, there is no need for loop, loop is used for processing, you will write str of i not equal to null and i++ this loop is very important, you will see this loop is being used in every string program so str of i not equal to null, if the string is not on a particular index, it means the loop will run, as soon as the null is found, the loop will be terminated and here we have written length++ after the loop is finished, we have printed length equals to % of the ellipse so we are printing length through %, you want the string to be printed, you want the string to be printed which we have read, so you can do that too so length of % is, and here we have written str so I have told you in the slide that to print the string, there are 3 formats, in printf there is % or put a slip or loop, so we have used the first one so this str will be printed on this position and the length will be printed through %d so let's execute and see so first of all I am putting the country's name, India, so look, length of India is equals to 5 properly run the program and we run the loop control till null it means i, n, d, i, a, after a got null and the loop stopped there, the value of length is 5 let's execute it again, now let's put a small name like USA so length of USA is 3, program is working properly so in this way you have to control the reading printing now if I write here instead of scanf, so you don't have to put this % as me so keep in mind scanf, int, float, care, anyone will read it, int, float, care string, you can read anything but gettas is only for string, so let's use it as well now I will put space, you pay attention, I will put space and it will count like u, space, s, space, a, length of USA is 5 so u, s, a, 3 characters and between them there was 2 times space so total length is 5 and why did we get this read because we used gettas now I will comment on gettas and I am writing scanf again so I told you that scanf cannot read spaces so we will see that so let's execute this program now I am putting u, space, s, space, a so length of u is 1 after u we didn't do anything because we got space so if you want to read space as well, then prefer gettas if you don't want to read spaces without space then use scanf and this loop you must have understood how to print string we can print string through puttas we can print using % in printf so you can easily follow any method now let's talk about next program count, uppercase, lowercase, digits, spatial symbols stored in a string so we have counted total characters now we have to separate them uppercase, lowercase, digits, spatial symbols, count count characters count different characters here we write c1 equals to 0 c2 equals to 0 c3 equals to 0 c4 equals to 0 so c1 uppercase, c2 lowercase, c3 digits and c4, spatial symbols here I am writing enter a string now we will use gettas so mostly we use gettas because we can input space and we will prefer this for loop for loop is same because we have to run loop till null but we have to process all characters before null now if you have watched my video in which I told you about ascii value we have checked the input from one character user which is uppercase, lowercase, digits, spatial symbols now we have many characters in string so we have to count those things here we will use ascii values so if str of i greater than equals to 65 and str of i less than equals to 90 so those who have not watched ascii values then you will get those in the beginning so you will see the range of ascii values now I will give you a device capital A is ascii value 65 and capital Z is 90 so any character in the range it means it is uppercase so we will give c1 plus plus else if str of i greater than equals to 97 and str of i less than equals to 122 so c2 plus plus so this was the range of lowercase if you have written lowercase letters small a,b,c,d then there is ascii value of 97 to 122 then if str of i greater than equals to 48 and str of i less than equals to 57 these are digits 0 to 9 they will count and if there is no match then it will count in c4 this is the complete loop now we have to print the results so you will know the range of ascii values and ascii values are used so that we can do comparison if you don't remember ascii values then you can write it like this in single quotes capital A, capital Z small a, small z you can write it like this so the character constant it will convert it in ascii values so you don't have to write ascii values it will do your work then we have written print f upper case is equals to percent d c1 I am copying this so all these are 4 times this will be lowercase and it is for digit . . . . . . . , यो समच्ठ में आग लेए वह की होगा कि हम बवोशरे करेक्तस को एकी वीरीएबल में, जो की श्टिंग है कैसे स्टोए करें, कैसे स्टोए रीड गर बाया और कैसे लुप चला कर उसको प्रोसिस आगा. आपका यूज भी समज में आगया होगा योगी साईस 20 था बत हमने 20 केरेक्तर इंफुट नहीं करवाएते बत फिर भी हमने उसको कंट्रूल कर लूप को किस के तूए नलके तूए तो लूप लूप लूप लूप रीटिंग, प्रंटिंग, प्रोसेस अप पहले वोड को समज लेता है बैसिली होता कै लेट सपोस एक एक एकजामपल लेता है यहा में एकजामपल लेरों की मेरा जो इंपुत है वो है C is a programming language तब इस में कितने वोड है पहला वोड है C, वोड है इस फिर वोड है तब इस में कितने वोड है पहला वोड है C, वोड है इस फिर वोड है A, चोथा वोड है प्रुग्रानिंग और पाचो वोड है लेंगज तब वोड का पता कैसे चला की जैसी एक सपेष आता है तो एक वोड कमप्लित जाता है स्टिर अफ आई दब लेंगज तो सिंगल कोट्स में डाल दिया स्पेस और या लिग दिया स्पेस प्लुस प्लुस तो ये लूप नलतक चलेगा और जिस दिस लोकेशन पर स्पेस अवेलेबल है उतनी ही बार स्पेस काून तो जाएगा अगर लेँव काून तो जाएगा और वेल्गार स्पेस प्लुस भीडियाबल लेगल अगलेबल होगी तो और वो भो दोनोगो प्रिंट करादेते है बैख शलच या जाएग ये तो शीपन्धी बैख शलच या वोडभ ये ईगज तो चोप रष ये नहीं तो लेज तर इकणटर श्विंज अबलेभल आभ गो ख़ा अपर केस उसको क्या बनाना है लोगर केस तो अपर केस को लोगर केस बनाने के लेए आपको करेक्टर में 32 आद करना अद आआ आआ ये भी हम पैले वलडी पर चोगेuso उसक्ट आप मै फ्पबडीون सिर्चोगित अप भाँगा,ोगी ईू आप मै दीवए ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ ॐ  which is minus third after that print your spin now use the potency that you can also know in the potency you have to add your spin ok now the upper case will get converted into lower case and the lower case in the upper case we will execute it now I am inputting my name look s a n j a y so I have added 3 uppercase विर्स्बिधियों