 Hello friends, I am Sanjay Gupta. In this video I am going to demonstrate you how you can count how many words are available in a string. Before starting you can note my information. You can follow or subscribe my youtube channel through the link youtube.com slash sanjaygupta underscore tech school. You can download my programming app Techimus which is available on Google Play. Now I am going to implement this solution in C programming. So first I am including a header file that is stdr.h. Now I am defining main function. Inside main first I am declaring a character name that is str. Now variable i and c is equals to 0. Now if we want to count words in a string so first we have to understand what is a word in a string. So if we take example of this sentence. So here you can see total 5 words are available. So word is terminated with a space. So count is one word because after t there is a space then words because after s there is another space then after n space is available then after a space is available. So here you can see total number of spaces are 4 and total number of words are 5. So to count number of words in a string we can count number of spaces. So if number of spaces are 4 that is available in this sentence. So words will be spaces plus 1. So suppose there is a sentence in which only one word is available. So that will be containing zero space. So whenever we count number of spaces in a sentence then number of words will be spaces plus 1. So in this program I will be counting number of spaces in a sentence then I will be able to find out how many words are available in that sentence or string. So first I am going to display the message. Enter string through this printf then to receive that string I am using getis function. Now I am applying a for loop which is starting from zero then condition is str of i not equals to null and then i plus plus. So if condition str of i not equals to null is true then only this loop will repeat. So here I have to check if str of i double equals to space. So you can see I have applied space in single quotes and str of i is compared with this space. So if a connector which is available in a string is equals to space then I am counting c plus plus. So if this condition is true then only c will be incremented by one otherwise not. So c will be counting how many spaces are available in a string. Now after completion of this loop I can print words equals to percent d and then c plus one because words are equals to number of spaces plus one. That's why I have printed c plus one and at last return zero. Now I am modifying this size of string. So you can see I have implemented the logic in front of you which is counting number of spaces and after completion of counting I am printing spaces plus one which is the quantity of words. Now I am executing this code. So here I am typing India is great. So here you can see total number of spaces are two. So that's why this sentence is containing three words. So you can see the output words equals to three. So this way I have counted number of spaces and after adding one in number of spaces I am able to find out how many words are available in a string. I hope you have understood the logic well how we can count number of words in a string. If you want to watch more programming related videos you can follow or subscribe my YouTube channel through the URL youtube.com slash Tanjay Gupta underscore tech school. You can download my programming app Techimus which is available on Google Play. Thank you for watching this video.