All language subtitles for 6. Strings - Input & Output

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
hu Hungarian Download
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 to another video in our programming course.

And in this video, we're going to continue talking about strings and in particular, we are going to

learn about some input and output functions.

So at this point, we know how to initialize an array and the string.

And in this video, what we are going to do is to take a look at how we can read some input and storied

as a string, as well as how we can print a string.

Just by using one line of code instead of the loop we've used in the previous exercise.

And we also are going to talk about additional input and output functions that we can use for strings.

So that's what we are going to learn in this video.

And actually, this topic is very important because it will help you to proceed with the challenges

that we are about to do in the next videos.

So simply saying with a raise arrays of integers, for example, we know that we can use a loop to run

over all the elements and use the scanning function to read as input values from the user and store

them inside of these elements one by one.

In this for a loop, meaning that for every element in these grades array, we are going to scan in

separately.

And that's exactly what we can see here in these for loop that we are using a scanner function for each

of the elements of the grades array.

And we can say that it will be also the same if we would use an array of floating points or an array

of charges.

Right.

They they use Iranian.

They're running the loop over and over again.

All the elements are simply would be it would simply be the same.

Right.

But what about strings?

Will there be any difference?

Because we previously said that the whole point of arrays of chars with a backslash zero at the end

of it is that we will be able to treat them as strings.

And it will it should provide us with more functionality and more options to work with it.

Well, with ease.

So let's take a look at how we can use strings as an input.

So relink strings as an input from the user is much easier than working with a raise.

Let's say that we want to read some string from the user and the string.

Will we present our first name?

And we will assume that it will be up to nine characters.

So we will, first of all, create an array of characters of size stand right.

Why?

Easy to say stand because we want to keep some space for the last character.

The backslash zero with the end.

And now the way we can read these string from the console and store it inside the first name is very

straightforward.

We just use the scanner function that we are well familiar with and we specify the percentage as to

is a placeholder to read a string from the console and story inside first name.

So once again, here in the first name we can read a string up to nine characters because the tenth

character is held by default for the null character at the end of it to specify that it's a string.

And we are using a percentage as place holder to specify that we are reading a string.

So basically you can also set some limitations on how many characters you would like to read from.

These are from from the user, from the string.

For example, if you know that the limitation will be just of nine characters, let's say not including

the null at the end.

Then you can modify a little bit your scan F to look like this.

Okay.

So this way, when you specify the percentage nine it's specifies.

It's actually it's sort of a security mechanism that specifies what is the length of the string that

we are going to read from the console and story inside the first name or array of character that we

we've created to hold the string.

So if the user happens to write more than nine characters, then you will just read the first nine of

them and they will simply prevent from different other unexpected things that could be happened if the

user inserts something there is that we do not expect.

So to read some word from the user as an input.

We will use the scanner F and the percentage s place holder and after the comma, you type the name

of your string because it represents its address.

And there we are going to store the input.

So I hope that's clear.

We are reading, for example, here we can see the user inserts are at 12 characters are soaring and

the program reads just the first nine of them in storage.

Side of the first name or array of characters in the first name String.

So we've seen how we can use a string as an input.

Right.

And now let's take a look at how we can use it as an output.

So if you want to print a string, it can be simply done in just one line of code.

You could simply use the percentage as a place holder to print your stream.

So instead of just using some loop.

Right.

Like we've done previously to print every character in an array of characters.

Scenes that we know that first name.

Right now it is a string.

And we said that there are additional functionalities that we will be able to use for strings.

Then we can see that in just one line of code.

We can print the whole string.

So, for example, if we have our first name, let's say it's John and we use these print off-line.

So print F percent, the jazz and.

And then we specify the string to print.

Then John will be printed to our council application.

So simply saying we have no for loops, no iterating over each and every one of the elements.

Simply use a percentage as place holder.

And you are ready to go.

And let's add another example.

Basically, we've used a password previously that looked like this.

Right.

And it doesn't matter if we initialize it, if we initialize the string or if we read it from the user

is an input using some scanner command, for example, like we've seen previously, we can still easily

print this string through the screen just by using these primitive commands.

So print out percentages and the name of the string, the array of characters with the null suffix.

So I hope that's clear.

And you see the difference between printing.

I used a string versus printing an array of characters.

And now let's take another look at this caniff example.

So we've seen the this caniff works as expected when we use it in conjunction with the percentage as

place holder and reading the input into a string.

But the problem is that we checked it out only using one word.

Right.

So what will happen if the string is more than just one word?

For example, if we use a hello world text, right.

It simply consists of two words with some space separating between them.

So we will, first of all, create an array of characters of size 20 and then use a regular scanner

function to read some string from the user.

And in this case, it's going to be a string of hello world.

And once this kind of function is done, we expect that all of these string, including the the space

character that is between the Hello and the world words.

Right.

We expect that these whole string will be stored in SDR since we used a second F function.

And now if we use some print F line, right.

To print all the string that is stored in the SDR variable in the SDR, all let's c array of characters

or a string in this case, we will see that if we do, if we run this print off command, then on the

output side we will get just the hello word, not the hello world, but just the hello world only.

Hello.

Without any world.

And what happened here, and it's very important, is that this kind of function can read the first

characters up to the space character.

It's sort of a delimiter for it.

So it will only take the hello's Thring and storeyed inside of this SDR.

And one of the ways to overcome this sort of limitation is by simply using the Gettis function.

So how it looks like very simple, just use the getters function, specify the SDR, where we should

see where we should store the string that we read from the console as input.

And there you go.

Your string will be stored in this D-R, including including all the space characters.

So they are previously disconnected, did not provide us with such functionality.

So if we try to print out what is stored in these are right.

Using the same print to function, the printer is the same here.

We will see that the Hello world as an input will be seen also as an output.

So in this way, you are reading the whole text.

Not just one word until the space character.

So the main difference between F and get s.

Is that get as simply reads text and stores it, including spaces, and they're supposed to scan if

that reads characters of only the first word, just the first word, we read it.

And if there is some program that you've developed that should read as an input, just one word, then

probably you should consider using scanner.

But if you know that it's valid for the user to provide us Treen with more than just one word.

For example, if you want to read both the first name and the last name from the user and then story

in just one string, that's also OK.

But just use the getters function for that.

Oh, and by the way, there is also another friend for the get us function and it's called the Porter's

Function.

So put s stands for put string basically on your screen.

Right.

It allows you to print out on the screen your desired message.

Similarly, like you done it using a print of printed function.

You can do so just using the progress put s SDR and specify what string will be printed out to the screen.

And both of them are pretty much the same.

There is only two, let's say, differences between them and one of them is that the put his function

automatically appends a new line to the end of the string.

When it's printed out to the console, you will see a new line after this, after after these given

string.

And that's opposed to the print of command, right?

It will not by default.

Add a new line.

You need to specify a backslash.

And whenever you want to, to jump one line ahead.

So if you want to print a string, you use print F percentage ask and then you use a backslash.

And at the end of it, to get one line, but put as does not does not require that it already spans

a new line by default to the end of the string.

And the second difference is that the printed function simply allows you to make some more formatting

using that percentage DB percentage F.

And so any, any, any kind of are constructing different messages using other formats like integers

and floating point.

And that's opposed to the put as which is simply used for putting strings to the screen.

So for example, you can use this line of code to print information about a string and to add some for

Matt specifiers for integers and also add some another message like my name is before the string itself

and so on.

And then I use this place holders to make your message a little bit nicer.

So I hope that's clear.

And you understand the difference between the get and they are SCANA F percent, the jazz and the differences

between put s and print F these are not so let's say not so big differences, but it's very important

that you will know all the differences and then you will not get stuck while creating your new programs.

And I guess that's it for this video, guys.

That's it for their input and output introduction using strings.

And I think that even if it took not too much video time, we still happened to cover up a lot in this

video.

And you now have enough tools to start solving exercises on your own.

So let's start with a simple challenge, shall we?

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