Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
So I hope you got yourself some time to think about the solution, and now what I want us to do is to
start solving the exercise so we have to find down how many words.
Let's just point out these here.
And what was it?
Find out.
Find how many words there are in a string.
OK.
So the first thing that we were asked to do is to create to create a string.
So let's use something like this Charlot's year sentence.
OK.
So this will be a string.
Let's make it a size 30.
And basically, we declared an array of characters that will be used to hold a string.
So the next thing that we are going to do is we are going to print some nice message.
So to the user printer.
Please, please enter.
Enter.
Let's say a string, a string or some text string or some text.
And now what we are going to do is we are going to use the get this function to read the string from
the user.
So get us.
And here we will have ah, we will have what we will have.
The sentence itself.
Right.
Maybe you're more familiar with using CHA as the arm to create a string.
But this is just the name.
We will simply use it here.
So now once we've read the string from the user, from the console application, it will be stored inside
of this array of characters representing a string with a null character at the end of it.
And now what we are going to do is simply to assume let's just for the beginning, will there take the
text that we use there?
What was it?
Hi, my name.
Something like this.
My name is glad if I'm not mistaken.
So this was our previous text or a previous string.
And what we will assume that we have a what will be our separate.
There is this space and that we have one space between every word.
So this is kind of our assumption will also create two additional variables.
Let's call it something like count words, which will represent the number of words.
And we will specify that it will be zero and we will use an additional variable.
It's C I.
That will help us to iterate over each character in this string.
So we know that we can run are basically on these string.
Let's let's create something like this.
OK.
So let's also add in it.
No, no.
We don't need these and we just will use these for a loop.
So four equals two zero.
As long as I is less than then what then.
SDR land is your land of sentence.
OK.
So we know we will run from my equals to zero until the last time.
The backslash zero character.
And we will increment I by one on each iteration.
And we know that if we want to use the SDL in function we should include include the String Dodd H library
that we've just mentioned.
Now what we are going to do in these for a loop is simply to check where we have the space character.
So whenever we come across this space character, we will assume that a word that some word has ended
and a new word has started.
So we will simply do something like these will use this simple condition if sentence.
Sen.
Sen.
Dan's sentence at Index I.
So if a given character equals to a space character.
So in this case we are going to implement the count.
Words by one.
So count horse plus plus.
And this way what we are going to do is simply to either read over all of the string we've got from
the user and to count the number of the number of space characters in this string.
And based on this result, we will assume that though there will be these exact number of words.
So that PIN B will work.
OK.
But let's say it was just kind of our assumption that there will be just one space character.
But let's assume that that's the case.
And we will also we will also use here that print off-line to print the results of print print F on
the total amount, total amount of Maude's in percentage as equals to.
Are centage d backslash n in hearings that of percentages.
We are going to specify the sentence.
And instead of the percentage.
We are going to specify the count words.
OK.
The number of words in this string.
But the thing that interests us here is should we add additional last plus oken.
And the increment the count of words by one, because if suppose we were, we had only two words.
So it will look like this high mile, let's say.
And we will simply see that there is just one space character in this string.
So that's why we want to we know that there is a separator and meaning that it will count the one on
the left.
And also the one on the right.
So that's why we will use outside of the for a loop outside the slope.
We will use also the last incrimination by one.
So now we've we will print this result of the screen.
We will see the number of words in our text.
So let's try to build and run it.
So go here to the Beeld and Iran and let's say hi, my name.
My name is.
OK.
And we expect that the result will be five.
Right.
So we can see that if we write run this program.
Total amount of words in hi my name is Vlada equals to five.
Not exactly specified correctly.
Let's just do something like these.
I don't know, just use it to specify that this is our strength.
So let's build in running once again.
Hi.
My name is Vlad.
And let's see so we can see here that the total amount of water in hi my name is Vlad equals to five.
And that's exactly what we expected.
We expected to count the words based on this space separator that we know that a space character separates
between different words.
And what basically interests here, me and also probably you, is the fact that there is a lot of strings
that probably will not be so conventional and just use one space character like we counted here between
two different words.
So, for example, we may have a space at the beginning, for example.
This is our string, right?
Previously it was like this.
And I tell you that there isn't a chance that a string starts with the space character.
Right?
Maybe by mistake, maybe no.
And in this case, our program will not return the correct result.
And also, it may be on it at the end of the string.
OK.
You may have here a space character or maybe between two different words.
You may have a space character or two.
So this program, it works.
Okay.
If for for the basic case where you can assume that there is only one space character between two words
and a space character appears does not appear at the end or at the beginning of a string.
So basically what I want you to do is to upgrade, to develop some program, since you know how these
program works.
I want you to think of how would you upgrade these kind of simple program to support also these, let's
say, end end cases where you have to find out the number of words and where I can be, where there
can be a space character at the beginning, at the end, or maybe between them there will be, let's
say, multiple character space characters.
So how what what what would you change in this program?
So what will work?
Also for all cases.
So that's your task for today.
Your task is to develop this program and to try try different examples and make sure that it works as
expected.
That's how you will grow and that's how you will learn more about yourself, about your skills and about
how you tackled programs, problems in C programming language.
So thank you so much for watching, guys.
Keep on practicing and I'll see you in the next video.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.