Strings - Part 2 | C Language Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome to nourish technologies this is Shin was in the last session we discussed introduction to string handling in a c language and how to read the values and how to read the elements of a character array and how to print the character array also we discussed now one more example on a string handling here in the last program hash include so we are including that standard library and we are reading to read the elements we are declaring 1 character array name with the size 20 now we are asking printf enter name and here it is in the last program we discussed a scanner function I want to read a name % is s address no need to provide reasons we discussed very clearly because name is holding the base address and from the base address what all the characters you input character by character it will collect so here on the console whenever it is asking the message enter name enter name if it is a single word it is okay suppose we are giving like this Hari Krishna we are giving like this whenever we are giving a space between two words here it is in to the first string with the help of first % is s into the string name it will collect the value only hurry it will collect the value only hurry and here it is looking for the second percentage s to read the value Krishna but here it is we have provided only one percent is s format specifier here in a scanf so that is why only hurry it will collect and it will omit Krishna so later if you want to print printf printf name is percentage yes percent is yes we are printing the name in the name what is the value here Harry so it will print only hurry on the output screen name is Harry so using percentage yes we can read only a single word strings multi word strings it is impossible to read them sir one name contains how many words how we can understand of course it is not possible so then how to read sir so that is why instead of a scanner function we use a get s function what we use get is function see here in place of a scanf now we are using get s get as function means what is getting the string is reading the string here so what we have to mass format specifiers not required only just a name we are passing the name write variable value we are passing so how get s function will read get s function will read the complete character set into the array until you press Enter key if you do not press Enter key it will keep on reading either it is a space character or it is any special symbol it will keep on reading when it will stop sir it will stop only when we press Enter key okay for example if it is a scanf we can provide space right to differentiate the input values but in a Gatiss how many spaces you will give not required it is a sentence or it is a paragraph or it is a page until you press the Enter key it will keep on reading so here whenever whenever we are giving the space it will not consider whenever you will press Enter symbol so then only it will stop collecting the elements into array so now here it is instead of printing hurry the complete value it will print a Krishna the complete value Hare Krishna will be stored into the name and next whenever we are printing what percentage yes will do the last character is a null character null character until the null character all the characters it will print that is percent is yes that is percentages this is using a scanner function and using a Gatiss function to read the elements if it is a single word we can go for percentage yes if it is a multi word it is better to go for get as function either you want to read a sentence or you want to read any any paragraph and all okay we will see one more example here we have one header file header file is a string dot H header file string dot H header file so contains n number of predefined functions n number of predefined functions use it to process strings if you want to manipulate the strings if you want to process the string data we can go for string dot H library functions we will see one by one suppose one function is there STR LD in string length string length disease so what it will do what it will do means here it will written length of string length of string excluding excluding null character nothing but whenever it is returning the length it will not include null character is one length okay that means for example for example take any name any name for example sham we are taking last character is a null character the length is only four characters it will return the length is a four sir show me the exact prototype how they defined exactly that string length means observe here STR l ye n it is taking character array as an argument character array so more clearly character pointer character pointer sir I do not know what is a pointer no problem we will see in the coming sessions okay just consider as a character array it is taking character array as an input nothing but string as an input answer what is the output output is a return type is a size underscore T type questions are what is the size underscore T I didn't hear this datatype previously anywhere in a C language size underscore t is nothing but a unsigned datatype or unsigned integer value what is that unsigned integer value so previously so they are calling it as a size underscore T nowadays we are calling a unsigned integer sir why unsigned integer sir if you want to find the length of the string consider suppose if you are not passing any character the length will be zero if you are passing some characters in a string the length will be either 1 2 3 4 some positive value only definitely length will not be a negative value impossible case so inner data types unsigned means what is a positive value so length is always a positive integer value so that is why string length return type is a unsigned integer type return type is a unsigned integer type so now on this one simple example we'll see how to use a string length okay here we are writing the main method directly main method Here I am declaring a character array same name I am giving STR any name you can give and the size is also maximum 30 characters you can input and here it is we are asking printf enter a string enter a string and here it is we are reading is better to go for Gatiss multi-word characters also they can be Gatiss and we are passing STR then they will input after that I want to find the length of the string so where it is available the header file you have to include include string dot H header file you need to include and then we can call STR le n string length right we need to pass that character array what is the character array name STR so we are passing STR STR here it will return the length in the form of integer we are collecting into le and variable le and variable is better declare it as unsigned integer always a positive value it will written the length is a positive variable it is a positive integer value and we are printing very clearly printf very clearly here it is length of length of string in place of string what I am writing percent is yes I am placing in a single quotations also observe clearly percent is yes II is length percentage D that is also in single quotes if you want to place you can what we have two prints er in place of percent is yes STR string in place of percentage D what we have two print length length so in the output so console also I am writing on the output screen on the console first it will ask this message enter a string enter a string suppose here it is we are writing nourish I t simple message and whenever we press ENTER how many characters are there including space 1 2 3 4 5 6 7 8 9 not the null character only T so here length of length of that string it will place in a single quotation so nourish I T in a single quotations is the length is a 9 it will print 9 is also in single quotes this is output finding the length of the string finding the length of the string okay so using string length function we are calling string length function is taking character array so what string length you want to find out that you have to pass as an argument and how many characters are present excluding null character it will not include that null character excluding null character it will return a positive value positive integer value so length variable is of type word unsigned integer time this is simply how to find the length of the swing okay so in this session we have discussed about Gatiss function and so one predefined function available in a string dot H library that is string length function in the next session we will see how to find the length of the string only but without using string dot H header file functions we are not depending on write predefined functions we can write our own logic control statements logic right we can write user-defined logic to find the length of the string okay for more videos so please subscribe to nourish ID channel thank you
Info
Channel: Naresh i Technologies
Views: 365,560
Rating: 4.9158273 out of 5
Keywords: C Language, Strings in C, Srinivas, Naresh IT, Hands on C Language Training, C Language Demo, Online C Language Training, C Language Tutorial Videos, C Language Overview, C Language Interview Questions
Id: 9633Qh2E9H8
Channel Id: undefined
Length: 14min 45sec (885 seconds)
Published: Fri Sep 09 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.