 Hello friends. I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I'm going to explain how you can count characters and words in a stream with the help of C language. So before start, I want to share my information. If you go to detail or description of this video, you can find links of various playlist related to C language so you can watch them. Now, I am first taking one example so that we can understand what character and what word is. So let's say, so I have this character added and these are the indexes. So total 12 indexes are there. It means a total size will be 13. And now I'm going to put some content in these blocks and we need to identify how many characters and how many words are there. So character means any alphabet, desert or spatial symbol whereas words means whenever we have one space. So before space, whatever is available is treated as a word. So let's say, so this is the complete stream. So here you can see first five characters are in India, then we have a space that is there again space that is great and then null character. So now it is having total 15 blocks. So size will be 15. And suppose its name is SDR. So this is the input screen. Sorry, this is the input screen provided by the user and here we need to identify number of characters and words. So character means one, two, three, four, five, six. So space is also character because it comes under the category of spatial symbol. So six, seven, eight, nine, 10, 11, 12, 13, 14. So 14 characters are there. It means whatever is available in the stream before null character will be counted under the category of character. Whether it is alphabet, desert or any spatial symbol or let's say it is a space as well. So space is also a spatial symbol so that you need to come also. And if we talk about words, if we talk about words, so we have two spaces and here you can see three words are available. So instead of counting words, I will be counting number of spaces and if I add one to that space variable, then I will be having number of words. So this way I'm going to solve this problem. So now I'm going to write the program in front of you so that you can understand how we can perform these operations. So I am starting from main function. So first of all, I'm going to declare a character array and let's say his size is 15. So its size is 15. Then after this, I'm going to declare one variable i for loop counter. Then variable c which will be counting number of characters. Then variable sp which will be counting number of spaces. So initially this is zero. After completion of the counting, I will be adding one into this variable so that I can have number of words. So let's say if we don't have any space in a string, then also we have one word. So suppose we have this string like this. Null is available here and rest blocks are blank and string is only containing India. It is not containing any space. So what will happen? How many words are there? One word because without any space, if you're writing something, it means it is treated as a word. So if it is zero, then also I have to add one into it so that I can show you like one word is available. So I hope that out is also clear now. Then to print this, I can show enter a string message. Then to get us, I'm going to leave that string into str variable. And after this, I'm going to write a loop. Which is starting from zero. Now here condition is str of i not equals to none. So I'm going to check each index value of string, whether it is equals to null or not. So if it is not equals to null, then loop condition will be true and the operations will be performed. Otherwise, loop will be terminated and after termination of loop, I need to print number of characters and words. So this way it is completed now. This loop will repeat till this null character. So it will count all the characters. So I'm just putting C++ here because if loop is repeating 15 times, if loop is repeating 15 times, so every time I need to count this C variable because everything before null will be treated as a character. So that's why I need to count. And for space, I am writing str of i double equals to and inside single quotes, you need to put space here. And you can use this as p++. Right? So this way you can count number of spaces. If you don't want to put single quotes and space here, so you can put directly 32. So 32 is our sky value of space. Right? So if you write 32, then the character which is available on this index will also convert into its sky value. Both will be checked if they are equal, then space will be incremented otherwise. So you have two options. Either you can use space within this single quotes or you can write 32. Now after completion of this loop, you can print characters equals to percent. So number of characters will be printed and you can write words equals to percent. Now C and SP plus one. So C will be printed here and this expression will be printed. So whatever the number of space will be, you need to add plus one so that number of words will be there. So here you can see we have two spaces. So this SP will be incremented two times. But if we have two spaces, then we have three words. So it will be incremented by one. So correct number of words. So this way I hope you understood how this program is calculating a number of characters and number of spaces. And remember whenever you are working on string, you need to put this condition because you don't know exact size of the string. But you know at the end of string, we have null character. So you can iterate your loop with this condition like if characters are not equals to null, then your loop will repeat otherwise it will be terminated. So I hope you understood whatever I explained in this video. If you want to watch more programming related videos, open my channel, go to playlist or you can go to description of this video. There are various playlist links are available related to C language so you can watch them too. So thank you for watching this video.