47 - STRINGS or CHARACTER ARRAYS - C PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome to our Channel so into this session let us have a discussion on strings so extinct is defined as a group of characters so this thing can't be a group of characters so we know that the character universal language beings any key in the keyboard can be considered as a character so these characters can be alphabets numerous special symbols so everything will be treated as a character in our cylinder so this group of characters is called a string and we know that the definition of enemy so array is group of elements with same data so and either can be defined as a group of elements with the same data and character strings is a group of characters so every string can be implemented using character as the swipe the hot red plane for this strings concept is character pairs so if you want to implement the strings you should implement only by means of this character as so that means we have to create an array with a character data type so that we can store all the characters into that particular character array and GUP is also all those characters will form a string so the syntax is syntax for Strings is data thing here the data is character character followed by stringing the journey and we have to mention the size of the string so whatever makes up the size of the string and everything all the rules will be followed just which are followed while writing the and name anything one-dimensional ends so for integer values or a characterizes the rules will be the same so we have to mention the size in the declaration itself and if you do the initialization also then this size is an optional the size is an optional when declaration and initialization done in same time same line in same line what we call it as compact an initialization simply we say that if you take any integer variable we say that in da is equal to 5 this is a combined initialization so similarly in the comparative initialization if you write the declaration and initialization in same line then the size of an array is an optional so we need not mention the size of a credit so directly we can I set the element so that the compiler will treat you come up with the number of characters and it will be asking you to the array elements and here if you want to store 5 elements into an array we have to mention the size as 5 plus 1 because the last element will be the null character so as the compiler does not know where to stop the characters also in here the character I mean here the strings is a group of characters that means in words we can write words so the compiler doesn't know where the end of the string so for that couple end of the state knowing the end of the string the compiler will add a null character at the end of the string so if you want to store a final character string we have to mention the size as six because five for the characters in the last six segments is for the null character so let us have an example so that you can get so character name of six is equal to so how to initialize the characters are stinks to a camp rack similarly as we have seen in the fungal infection 11 you have to open the curly brace and here we have to remember is what we have to remember so here it is a character and each and every character will be represented in single quotations so every character is represented using single quotations so if here we have to bind so we don't know whether it is my line is integer or a character doesn't use a character or integer so here the mind is a integer and my in between the single quotations is it character normal value is an integer any any value or alphabet or any special symbol which is represented in single positions that we call it as a character so every character should be represented by using single quotations so we have to mention here in a single conditions we have survived the catches in a single perdition's so here we have mentioned that 6 SN number of elements so we have to initialize in the 5 elements or 600 so we have to essay by using single coefficients let it be H is a first element come on use a city good e comma y comma Y comma oh come on last statement I am making it as a null character here in the strings the null character null character is represented as slash 0 so slash 0 so I have written here slash 0 because so this is 0 but not whoo alpha be true it's not an alphabet war it's a numerical 0 slash 0 so slash 0 is it one character in the character so this / - means it's an end of the string so compiler does not know where what is the end of the string so compiler will insert the slide 0 at the end of the string and it will treat slash zero as a null character a null character and it will treat this slash 0 as an end of the string see here in this example I have created a main with the 6 characters and I have given 5 characters so in a significant issues and the last characters slash 0 then what about so here this size is an optional because he only in a single line except we are declaring an array and also initializing ni so we can write as character name off so we need to mention the size simply we can write h e l and hold /z so automatically the compiler will count the number of characters and it will assign the size to the adonai name so if we declare and initialize the array in the same line this size mentioning this size is need not that it's an optional then so as we said in the previous sessions in the one-dimensional array first in the declaration itself we have to declare an array with a maximum number of elements so that we will be character name is a poor name of 10 is equal to h-e-l-l-o ratio so here the the names and array which can hold a maximum of n elements and we have created and we have initialized extreme to this and it so H value is zeroth element here first element second element third element for tainment 15 0 1 2 3 4 5 what about name of 6 7 8 mind so this is name of 0 name of 0 1 2 3 4 & 5 so here what about the sixth element settlement 8 element and I did so here all these four elements are initialized to so as we have said in the one-dimensional additive if we declare an array with ten elements and if you miniaturize it at least one element in there added all the remaining elements will be initialized to zero so if you declare an array but not initialize it every element in the array will contain garbage values similarly here also if you initialize any one element all the remaining elements will be initialized to null character slash zero so here alternately we can also assign a string to the category Daenerys character name of six is equal to simply we can use our codes help so if it is a string so if it is a string it should be represent by using double quotations if it is a character it should be represent in a single quotations so here we have si is ring directly to the character so that's why I didn't mention here the curly braces instead of using this curly braces just I am using double quotes in this double course I am giving the next so here the hitch will be stored in navels zero he will be stored in name of one yeah it is stored in name of two and again L is stored in the name of three and 0 is stored in of four and finally my character will be stored in name of six because here hello and the last last element will be the null character so this is all about the direct company their compilation I mean the initialization let's compile a visualization of any string so both we understood up to here and now let us have a look on how to initialize a string using different functions at one time so obviously at one time initialization if you say that one time initialization we can have a function that is scanf function so we will use this kind of function and what it means of this kind of function so we can initialize the character array with the runtime so apart from this scanner function we can also use to load functions for reading the string at runtime so those functions are get cap function and get this function so probably we can use three different functions to read a string into a character what is as we know that exists scanf function another one is get cap function and get as function so let us see one by one the syntax a simple example so that you can clearly understand see coming to this area function scatter function as we know in this kind of function we have to specify the control space fair and ampersand variable name here we are using character and so here we are using available as Eric and here for reading the string there is a control space where first thing that is percentage yes control space fair that is percentage yes and in the standard the using of ampersand is not required so it is not as it is a character additive as in the character array so we did not use this ampersand operator and so so controls pressure is percentage yes so what is the syntax for scanf function so right syntax scanf write the percentage yes so it implies it is a string and name select an ad name so we return function here then amber say we need not mention the ampersand here so if it is a percentages and name so automatically the string will be whatever where I think of the keyboard and then hang yourself so everything will be assigned to the variable or add a new so before that we have to create what we have to declare the name as character name of 20 so this statement means name is an array which came my name is an added which can store a maximum of 20 English and for reading the away we have to use scanf function scanner percentages need select everything whatever we are writing on the keyboard everything will be stored and heal the constraint is so up to where it will read so what is the termination here so after very reduce it can up to vary can read the data means so there is a condition here the termination is space so it will accept the input until you press the space button so until you get the space it with whatever the information you are you are given to the system everything will be assigned to the character array name and that should be it is the size given size that input should be with the given size and whenever the compiler encounters the space automatically at the end of the string it will consider it as an end of the string and it will SN / 0 and it will store it into the array name so that means whenever the compiler whenever the user thanks the space button immediately the compiler will stops reading and at the end of the string the compiler will add the null character so the compiler knows whenever the slash 0 appears it will treat it as in null character right in end of the string so for example let us say that here the termination is space so before space we can write any data that means the scanner function is used to read a single word single words individual words so if you write here hello oh hello hope so if you consider this hello and I say to the variable name any name and in real way whenever it encounters the space auto really the end of the string that means so hello and they another thing it will consider and it will happen slash zero at the end of the street so whenever the space appears it will append the slash zero and it will consider it as an end of the string so scanf function is used to lead single goods single good so it fails to read a line of text scanner fails to read a line of text so if you consider if you give input as hello how if we consider just as hello it will not consider how because after the hello this is a space so automatically it will happen slash 0 and and it will consider it as an end of the string so this is our good scanf function now let us have a look on one more function that is get carriage get care function the name itself indicates get Cadmus getting the character reeling the character so at a time the compiler can bring only one character from the mantle people so we have to ascend this get care function to one variable so here the syntax is some variable name is equal to get their function so this KCAL function will read a character from the keyboard and assign the character to them one character variable simply like scanner percentage C signature so this scanner function represents it treats a single character similarly c h is equal to get can also it will bring only one character and that character will be assigned to given minimally so in other day so we have to use some iterative statements in order to take a more number of characters so in order to get whatever of characters the case we in order to read a complete line of text we have to using iterative statements that this may have to call repeatedly until we reach over in my character so here what is the termination so where the compiler will get the termination that means well it will consider as a termination so in this kind of space will be considered as a calculation and here /y n that means newline character that means enter button enter button so newline character on an enter button so it will read the data until the user press Enter button so here the interpreter means /n so as we know that in the printf you use slash yen the extra sconce constant slash yen so automatically it shows that the output must be printed in the next one so new line that is called a new line constant so the termination here is the termination here is slash here so until the character the you until the character right by the gate care function is a slash n it will continuously consider and it will be assigned to the given a nickname so in order to really complete string so string using more number of characters here we have to use some literal two statements to execute this single statement repeatedly and we have to assign each character into n camera here we are assigning this little function is assigned to character so each character should be assigned to the character so here the termination is unit so this gate cap function is used to read the data until the user press the Enter button that means one line of text can be given as input to the character array using this gate cannot see so how let us see the example forgetting the characters so we can use learning CH not equal to CH not equal to slash yen so until this condition becomes true the body of the loop will be executed here we can write C which is equal to get cap so we have we assign this character to string name of ie is equal to CH and implement the algorithm hydrous so before that I is equal to zero and insurance character name of Fundy come on seen it it so until this condition becomes true / young every character will be assigned to character variable and every character available will be assigned to character addict where I is equal to 0 starting from name of 0 and keep on updating this loop variable so I equal to 0 the first character will be same and I plus plus 1 the condition will be checked and again get can character will be read to the character variable and this camera variable is are saying - they have name they have been character and so this process is repeated so then it can accept line of text single line of text s input but you see get careful but here the only property is at a time that means the compiler can read character by character so with one character can reproducing this it can function so that we have to use this iterative statements whereas to work on this proper so we are moving to the third function that is get s get s function so here the name itself indicates get get s winds get string so here we have to pass one argument into this business function and that argument is stringy stringy or any name should be given a power given to the latest function so here also the termination is so where the compiler will treat as end of the string that means here the termination is a also this mash n that means enter so whenever the user press Enter until that the data will be given into the string that that was the data will be read to the given string so here the syntax is get us off string name Sydney more agony so directly the delta until the user press the Enter button everything will be decided to given string name so the convention is here also slashin similar to the get care function so one reference please indicate care only one character will be read and in the Gators complete line of text candidate and so he has gone into using iterative statements any iterative statements so let's see an example so that you can so character name of six simply we can write a gay test of name so the complete data will be the next line of text will be assigned to me let us have a let us do here the size moving to the maximum from happening so 200 elements 100 times 100 characters it can store so get us of main function will read a line of text until the user press / yep so this is all about the input functions standard printf sorry Stan get care and get us function so whatever the function we are losing at the end the compiler will happen / 0 so that the compiler works whenever the slash 0 appears in the string it will be treated as a end of the string so this will be used in printing the string by printing the string so while printing the string the compiler will only compare from slash 0 so only finals / / g whenever the slash 0 appears the compiler will treat the slash 0 as an end of string so it will stop printing the remaining elements of the string so here also similar to our input statements there are outputs treatments so there are also 3 output statements that is creative get boot camp and to this so first parent to this printf statement similarly as we know that creative we have to use a cut-off specimen and followed by the variable name here also we can write the syntax is printed in the inverted positions percentage yes as it is a string and followed by LED and that means see it will print every character until it reaches slash zero so it may be a single word or it may be a complete line of text whatever it may be it will just check for slash zero if you only checks on slash zero so whenever the slash zero appears immediately it will stop printing the remaining elements so it will drink this /c Verizon and of that strength so if the string contains so exhausting contains some name contains some hello hi so if it is a composition let us consider so name is Anne Haran name hello / 0 5 now if you use printf function here / yes name so it will print every character of a name array until it reaches slash 0 so that means H will be read it you will yes we did yes we did will be printed and whenever it sees them whenever it it encounters the slash 0 it will take the test end of the string so it will stop printing like a miracle so the only heaven will be printed on the output screen in this example in this minute so it will only come back for our only checks for slash 0 so it will print every element until it reaches the / - so it means for every input function the compiler will append slash 0 at end of the thing so this is a simple printf function that means here we can print a normal words a single words or a line of text so if you want to read the data if you want to read a word you have to the scanner function if you want to read a line of text you can use either get care function or Dennis Potter why we want to print the string you can simply use this printf function and output functions those are put Ken so this is similar to the give cabbage so get care the read a single character then put care will print a single character so this statement is equal to three their percentage see CH for printing a single tap so you have to print a group of characters that means in order to play the complete string again we have to use a tray two statements so here we have to use rec try two statements starting from I is equal to zero and where we have to stop wherever the compiler reaches slash 0 so name of I naught equal to slash 0 so observe here slash 0 is also a character so every character should be represented by using a single quotations then I dismiss I know care of new so automatically it will consider and you really break everything on the de speaks and similarly the are another function is putting sponsor so this is similar to the get S function put this function here no more arguments we can give sorry and so we can use put this off name so that it will print everything on the displacement hope you understood this input and output statements I hope you need not use this put can function on put as function simply we can use break your function you not to break the characters so let us write a program to read a string at the runtime and to bring the string and so we can really dance so may captain let us take a name of use a string string of hundred string of one then for reading the strength we can do say the scales could cannot sorry can get cannot get us similarly we can use the gas function get us of strength so all the data will be assented to the Iranian state until you until the user press a new line character so after reading I have to endure so here we let us say to the 3d function printf enter string so everything will be assigned to the name string and now we have to break the function so print the string again you write the printf function later the string is simple use the printf function printf percentage yes give the string this is a simple program to read a string from the keyboard and print the same on the display screen hope you understood this input and output functions so coming to this input functions so scanf get cap and geddes so termination forget cap and furnace termination for scanner phase space termination first gate carries slash ian and termination forget kinetics is of secession and coming to the output functions printf Gatiss and sorry printf put care into this so in all these three the compiler will print the text until it reaches slash zero so in the whenever you use the input functions either if you use a scanner for them to get a get care of get S at the end of the string the compiler will open the slash zero and it will consider the slash zero as an end of string so by using this printer output functions either printer for care of today's so it will check for the slash zero in the string and if it falls the slash zero it automatically treat that as a end of the string so it will print every character until it reaches the smash zero hope you understood this strings concept so let us stop here so in the next session I will explain various string handling functions so that means is how to find the string length how to compare two strings how can get an extra two strings and how to copy one string to another string and everything so there are some string handling functions predefined functions we can use those prettified functions to perform these functions or we can use we can without using these pre different functions also we can find this length and we can copy the string or we can I'm cattle industry so everything we will see in the next sessions so I hope you understood this class and enter in the grass and if you are having any doubts regarding this C program feel free to post your doubts in the comment section so that I will definitely try to care for your dogs regularly and thanks for the listening thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 122,046
Rating: 4.8719668 out of 5
Keywords: sundeep, saradhi, kanthety, c language, c programming, cp, computer, computer programming, loops, strings, character arrays, arrays, array with character elements, printf, scanf, getchar, gets, putchar, puts, string handling, null character, \0, one dimensional array, %s control specifier, string array, c training, programming c
Id: ka6cg9szUtQ
Channel Id: undefined
Length: 39min 21sec (2361 seconds)
Published: Sat Oct 14 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.