All language subtitles for 2. Format Specifications in C - Why And How They Should Be Used

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

Welcome back, ladies and gentlemen.

And in this video, we are going to talk about format specification, and that's actually a very important

video, a very important topic, because it's the bases and the core for some of the following sections

that we're about to learning this course.

So in the previous exercises, we've seen that we can use the printf command to display different things

on the screen, different text that was just specified between these double quotes.

Right.

And suppose that you have these following line of code print f I'm 20 years old, a simple line that

displays your age on the screen.

And next year you're going to be, what, like 21 years old?

Right.

Then you could just use print F I'm 21 years old.

And if you would run it, you would simply get the same result just with twenty one years old instead

of 20 years old.

So these two lines are pretty much the same.

We have the print F Command.

And we also have some text, some strain between these double quotes.

And all I want to do is to simply sort of separate this age of these 21 or 20 years old.

This number out of this drink text that buring between these double quotes, something like that.

Simply take a look at this one print f I am.

Resolved and then use a comma and after the comma, just the number that we extracted out of here.

And this percentage deal is just some sort of a place holder which will be simply replaced by the number

in our case, 20.

That comes right after the first comma.

So if you will try to build an round this program, you will see the same vexed, the same resolve displayed

on your screen as you've seen previously.

I am 20 years old.

It's the same.

Right.

So what happened here is just that these percentage, the this place holder was replaced by the number

20, which appears here right after the comma.

And if we want to change this line to support in the next year, then we should do something like this.

We should use print F I am percentage the resolve and just use 21 after the comma.

So the percentage they will be replaced by the first number that comes right up through the double quotes

right after the double quotes, comma.

And then this number, these 21 will be replaced here and it will be printed out to the screen.

I am 21 years old.

We simply tried to print the text that is within these devil quotes.

And we just need to replace these occurrences of percentage something percentage D or a percentage something

else with the corresponding value coming after the right double quotes or right after these first comma.

Good, good, good.

First of all, it works.

And that's also an accomplishment right now in the next section.

This thing, this whole reason why we use the format specification will become much more clearer to

you because we are going to study what is an input in how to read any input from the user.

And in this section, we will also understand the importance and how it's being used.

All of this format specification thing.

All right.

So now let's take a look at a couple of more examples.

So in the first example, we will be using more than just one place holder.

So here we have basically two place holders to percentage there, right here and here.

And both of them are going to be replaced with some values before being displayed on the screen.

Right.

So for the first percentage, the place holder will have its corresponding first number coming right

after these Dabic, these devil quotes and these first comma.

It's 20.

The number is 20.

And 20 is going to replace these first percentage deals.

So when printed out on the screen instead of these first percentages.

We will just see the number twenty.

And that's for the second percentage.

It will be replaced by the second number here, which is 21.

Is that clear?

There was nothing hard there or complicated so far.

Simply printing out some text on the screen by using some new guy that we've just introduced, which

is called a place holder.

So let's try to run it and see what happens.

All right.

So today I'm 20 years old, and next year I'm going to be 21 years old.

So twenty four this percentage the.

And twenty one for these present entity.

And also, please note that we haven't seen a new line here separating between the real text and these

default text.

And the reason is because we didn't use a backslash in here.

So that's just was a quick reminder for you to not forget using Backslash N at the end of the text.

Now, for the second example, let's assume their tower average grade is something like ninety three

point seven.

Well, that's pretty good.

And if that's the case, you're doing pretty great.

So basically now what we would like to do is to print out these grade on the screen.

So basically my average, Grady's percentage, the ninety three point seven, and instead of their percentage,

the place holder would like to bring this number.

And now I want you to open up code blocks and to try to run this line on your own and see what happens.

I guess that ninety three point seven is not exactly what you can see on your screen.

Right.

You've got some strange number, don't you?

And for some of you, the number printed may also be not so strange and will be something like 93 just

without the remainder of point seven.

But clearly, you shouldn't get the expected ninety three point seven on your screen.

So ways that you see guys, these percentage displays holder that we've just used here.

We also use this thing, the previous example for format specification, meaning that these percentage

de was used.

Also, let's say, to replace numbers of integer for math like 20 and 21.

And when you are trying to use these percentage D to re to to replace to be replaced by some sort of

a floating point number, like ninety three point seven, an unexpected behavior and results will probably

be noticed, for example, like you've seen right here.

So if you want to use the place holder and format specification correctly for floating point numbers,

then you should use the percentage F just something like that.

My average grade is percentage F ninety three point seven.

And now if you will try to run it, you will see your grade probably with a lot of vier is with a lot

of zeros at the end.

Which is also K.

Right.

And this is ninety three point seven.

And although there are a lot of zero was at the end, the numbers still remains the same.

And then C land, which you can limit the total amount of zeros after the floating point just by specifying

how many digits you would like to see on the screen after this floating point itself.

So, for example, you specified point one before the F.

And this means that there will be only one digit after the floating point.

Exactly.

As you can see here, there are no zeros after seven.

All right.

Good, good.

Now, you know what is a format specification?

These percentage D percent, a Jaff and many others are simply used as a place holders with some format

specification like we've just discussed, for example, percentage.

They will be used for integers while percentage F for floating point numbers and percentage C for characters.

And many other options are basically available in C programming language.

So I hope that makes sense for you because we are going to use that a lot in many Constellation's during

our course.

So last thing for this video.

We've previously said that practice is one of the main things in these course.

It's necessary for you to write and execute some code on your own.

So I'm going to give you 10 exercises of format specification in the next PDA file.

And I want you to try to take a look at them to think what will be printed to the screen.

And also open up code blocks and try to run it on your own.

Make sure that what you thought that will be printed on the screen is actually printed out.

And if it's the case, so you're a good you know that you cover it up.

This topic in a good way.

But if you see that something went wrong.

Try to figure out why it happened, why the results you see on the screen are not expect.

Not not the same as you would have expected.

And that's one of the most important things in learning C programming guys to practice, practice,

practice, practice, a lot of guys.

So thank you for watching.

And download the PDA file.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.