Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,480 --> 00:00:08,310
All right, so in this video, we are going to talk about the F Gettis function and basically this is
2
00:00:08,310 --> 00:00:11,490
another function for working with strings.
3
00:00:11,670 --> 00:00:19,830
OK, so similarly to the pair that we've worked with in the previous video called the protest function
4
00:00:19,830 --> 00:00:23,160
and the F protest function, we just explained them.
5
00:00:23,160 --> 00:00:29,700
Right now we are going to talk about and show you some similarity between the GETAS function and and
6
00:00:29,700 --> 00:00:30,990
the F getas.
7
00:00:31,830 --> 00:00:40,230
So probably you remember the Gethers function that we worked with in the strings section to get s function.
8
00:00:41,160 --> 00:00:47,130
And these function basically was an abbreviation for get string.
9
00:00:47,760 --> 00:00:55,740
So basically what they get this function is simply reading or better say, getting a string from the
10
00:00:55,740 --> 00:00:58,140
user, from the console application write.
11
00:00:59,080 --> 00:01:07,690
Simply reading a string from the console and storing it in some variable so we could use it in our program
12
00:01:08,200 --> 00:01:12,910
in the F, this function is actually very similar to Gettis.
13
00:01:14,030 --> 00:01:23,120
It also gets a string, but that doesn't necessarily have to be from the console, but rather the get
14
00:01:23,240 --> 00:01:28,730
function can read a string from a file file, get string.
15
00:01:28,920 --> 00:01:34,520
That's the reason why it's called F gets simply get a string from a file.
16
00:01:34,970 --> 00:01:36,110
Are we clear so far?
17
00:01:37,000 --> 00:01:45,520
And now let's talk about the Afghanis syntax so the Afghan press expects to get as its first argument,
18
00:01:45,820 --> 00:01:47,230
the string name.
19
00:01:47,650 --> 00:01:54,670
It is the actual string where we are going to place the string from the file we are about to read in
20
00:01:54,670 --> 00:01:55,900
the second argument.
21
00:01:55,930 --> 00:02:02,690
We should specify what is the maximum size of the string we are going to read from the file.
22
00:02:03,040 --> 00:02:08,600
So basically, it's just kind of a limiter to the number of characters we are going to read.
23
00:02:09,220 --> 00:02:15,160
We don't want to read more than we can actually store inside different variables.
24
00:02:15,160 --> 00:02:15,500
Right.
25
00:02:16,210 --> 00:02:18,060
We have specific size for this.
26
00:02:18,910 --> 00:02:25,330
And lastly, since we are talking about getting string's from a file, we should also specify from what
27
00:02:25,330 --> 00:02:28,380
file we are going to get these strings.
28
00:02:29,020 --> 00:02:36,640
So we should specify here probably the FP, right, which is a file pointer that we created to point
29
00:02:37,000 --> 00:02:41,440
to our file, basically using the F open function.
30
00:02:42,370 --> 00:02:42,970
Awesome.
31
00:02:43,540 --> 00:02:47,110
So let's talk about how it works in practice.
32
00:02:48,010 --> 00:02:55,210
In this example, I created an array of characters, my string of size, I created some count variable
33
00:02:55,210 --> 00:03:00,370
that will assist us in printing some nice messages through the screen to demonstrate how the process
34
00:03:00,370 --> 00:03:00,750
works.
35
00:03:01,390 --> 00:03:06,520
And here we have F.P. a pointer to file FTF open.
36
00:03:06,520 --> 00:03:08,550
We are opening some file for reading.
37
00:03:08,560 --> 00:03:10,060
Let me show you this file.
38
00:03:10,390 --> 00:03:11,160
Here it is.
39
00:03:11,500 --> 00:03:12,470
This is The File.
40
00:03:12,490 --> 00:03:14,490
Hey man, this is lot from Alphatech.
41
00:03:14,500 --> 00:03:15,900
Do you love the course so far?
42
00:03:16,150 --> 00:03:16,710
That's it.
43
00:03:17,380 --> 00:03:22,770
And then we ask you, F.P. does not equal to now, meaning the file was successfully opened.
44
00:03:23,290 --> 00:03:25,720
Let's do the following thing.
45
00:03:25,960 --> 00:03:32,740
Let's use the F getters function as part of some while loop and on every iteration.
46
00:03:32,890 --> 00:03:42,700
What we are going to do is basically to read ten characters from FP where FP points to and store them
47
00:03:42,700 --> 00:03:43,800
inside my string.
48
00:03:44,320 --> 00:03:48,940
Just remember that the last three, the last character should.
49
00:03:49,930 --> 00:03:56,680
B, basically also for the backslidden zero at the end of the string, you do remember remember that,
50
00:03:56,680 --> 00:03:57,010
right?
51
00:03:57,730 --> 00:04:00,270
So let's run this program and see what happens.
52
00:04:01,210 --> 00:04:06,070
So click on the local Windows debugger law, where is the file itself?
53
00:04:06,430 --> 00:04:09,820
OK, here is the file and here is the result.
54
00:04:09,820 --> 00:04:12,210
And I want us to make a little comparison.
55
00:04:12,880 --> 00:04:19,450
So string number one, Red Hamen, OK, we can see that this line is less than 10 characters, so there
56
00:04:19,450 --> 00:04:20,320
is no problem.
57
00:04:21,190 --> 00:04:27,070
And also, we can see that we have here a backslash and printing a new line.
58
00:04:27,640 --> 00:04:29,020
OK, good.
59
00:04:29,320 --> 00:04:37,030
So actually, if we take a closer look, we will see that Hamen ends with the backslash and with a new
60
00:04:37,030 --> 00:04:37,870
line right here.
61
00:04:38,410 --> 00:04:45,790
And if we read it, we can see that there was a backslash in right here and also there was additional
62
00:04:45,790 --> 00:04:47,480
backslash in right here.
63
00:04:47,530 --> 00:04:49,000
So what's going on?
64
00:04:49,010 --> 00:04:50,770
What is happening here?
65
00:04:50,880 --> 00:04:59,860
OK, we can see that for the second time in our iteration, we read three numbers to read.
66
00:04:59,890 --> 00:05:06,100
This is V, so it was like four characters, five, six, seven, eight, nine.
67
00:05:06,460 --> 00:05:10,210
And the tenth character was basically for what?
68
00:05:10,930 --> 00:05:12,590
For the backslash zero.
69
00:05:12,970 --> 00:05:18,550
So this was like nine characters plus the Bixler zero STORIN Inside my string.
70
00:05:19,150 --> 00:05:20,800
OK, awesome.
71
00:05:21,260 --> 00:05:26,200
And here we see that we have like one, two, three, four, five, six, seven, eight.
72
00:05:26,200 --> 00:05:27,130
And that's it.
73
00:05:27,280 --> 00:05:30,280
So what's going on here is another one.
74
00:05:30,980 --> 00:05:37,150
Basically here was probably also the space and after that, the backslash zero.
75
00:05:37,630 --> 00:05:46,660
But lastly, one thing that I want you to understand is that the F Geddis function is used a little
76
00:05:46,660 --> 00:05:50,830
bit differently than the Gettis in terms of that.
77
00:05:51,280 --> 00:06:01,090
First of all, you read a string from the file until it reaches the first backslash m so we didn't continue
78
00:06:01,090 --> 00:06:08,320
here to read like any parts of the second line, although we had like seven characters, including the
79
00:06:08,320 --> 00:06:10,240
backslash and its eight characters.
80
00:06:10,240 --> 00:06:12,520
We didn't read the T, for example.
81
00:06:12,970 --> 00:06:21,400
So the F Gettis function reads a string from a file until it reaches the first backslash M and if there
82
00:06:21,400 --> 00:06:27,430
is a backslash in character then it keeps it and just adds a backslash zero to the end.
83
00:06:27,790 --> 00:06:35,980
OK, so basically just keeping the backslash in and adding the backslash zero to the end of the string
84
00:06:35,980 --> 00:06:42,130
without making any replacements or how also the various function works.
85
00:06:42,130 --> 00:06:48,250
It reads until we reach some limit specified hearing this argument.
86
00:06:48,500 --> 00:06:56,800
OK, so whether we read, until we reach some backslash end or the total number of characters, including
87
00:06:56,800 --> 00:07:00,070
the backslash zero, that should be also specified.
88
00:07:01,010 --> 00:07:09,440
And if both of the specified conditions not deal the backslash then and not till these limiter are not
89
00:07:09,440 --> 00:07:16,360
satisfied, then the Afghan dysfunction will simply read the whole string up until the end of the file.
90
00:07:16,760 --> 00:07:19,370
And that's opposed to the get us function.
91
00:07:20,270 --> 00:07:28,970
Basically, the GETAS function did replace different backslash and with a backslash zeros here we simply
92
00:07:28,970 --> 00:07:31,770
add a zero to the end of the backslash.
93
00:07:31,790 --> 00:07:40,160
And in case that we have this type of rating, so finally the F get us function returns.
94
00:07:40,250 --> 00:07:46,010
Now if the operation of the reading was not successful, so there may be also times that.
95
00:07:48,200 --> 00:07:54,530
The operation of reading will return now when the operation was not successful and in this case, maybe
96
00:07:54,530 --> 00:07:59,990
the wire will not iterate anymore and it will indicate that something went wrong.
97
00:07:59,990 --> 00:08:06,580
And also, that's a good practice for you to catch kind of catch these kind of errors.
98
00:08:08,140 --> 00:08:17,260
So finally, to summarize both Buddhist's and get us and their Associated Press f protest and F Getas
99
00:08:17,800 --> 00:08:26,500
is just basically adding these prefix for working with files and specifying a little bit different functionality
100
00:08:26,830 --> 00:08:28,590
now for different cases.
101
00:08:28,600 --> 00:08:35,950
But the main principle is the same for working with strings and files and basically putting strings
102
00:08:36,160 --> 00:08:42,310
to a file, getting string from a file based on some rules that I've just specified.
103
00:08:42,820 --> 00:08:45,910
So you can also write down these rules, make some notes.
104
00:08:45,910 --> 00:08:54,130
And also a very important part is that you will practice on your own because only like that you will
105
00:08:54,130 --> 00:08:59,710
understand and you will have different questions that can be answered.
106
00:08:59,710 --> 00:09:04,270
And like this, you will improve and become a better programmer.
107
00:09:05,730 --> 00:09:13,740
So before we move on, I just want to let you know, guys, that now you are the new totally new level
108
00:09:13,770 --> 00:09:21,420
because you now know an additional important function for working not only with the council, but also,
109
00:09:21,990 --> 00:09:24,110
you know, how to work with files.
110
00:09:24,120 --> 00:09:25,560
OK, you know of various.
111
00:09:26,620 --> 00:09:33,310
Six functions you've been introduced in the last few videos, you know how to work with files, working
112
00:09:33,310 --> 00:09:40,240
with characters, working with different placeholders and files, working with strings and so on and
113
00:09:40,240 --> 00:09:40,800
so forth.
114
00:09:41,290 --> 00:09:44,560
So I think you can see how it will become handy.
115
00:09:44,590 --> 00:09:51,010
And if not, we are going also probably in the next video to see additional examples and exercises.
116
00:09:52,030 --> 00:09:54,510
So, yeah, thank you guys for watching.
117
00:09:54,520 --> 00:09:55,560
Keep on practicing.
118
00:09:55,570 --> 00:09:57,510
I will see you in the next videos.
11983
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.