All language subtitles for 4. Start with Files Steps and Syntax in C

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
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
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian Download
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,820 --> 00:00:03,650 Hi, guys, my name is Vlad is Alphatech. 2 00:00:03,700 --> 00:00:09,580 And in this video, we are going to start working with files in our programming language. 3 00:00:10,510 --> 00:00:18,040 So up to this point, we know some reasons as to why we should even start considering using files. 4 00:00:18,520 --> 00:00:26,470 And these concept, let's say, of files can be implemented in many programming languages like C, C++, 5 00:00:26,470 --> 00:00:27,780 Python and so on. 6 00:00:28,690 --> 00:00:35,290 But here we are and the tutorial of the course of C programming language. 7 00:00:35,440 --> 00:00:43,690 And we are going to learn how to work with these files in C, so guys get ready and let's go. 8 00:00:44,600 --> 00:00:51,350 And first of all, what I want us to talk about is a couple of different operations that may be done 9 00:00:51,380 --> 00:00:52,390 on files. 10 00:00:52,880 --> 00:01:01,220 So we will talk about creating new files, writing new files, overwriting existing files, reading 11 00:01:01,220 --> 00:01:07,730 from files and what is this operation of closing files even means and so much more. 12 00:01:07,770 --> 00:01:10,790 OK, I think there was a lot of things we will talk about. 13 00:01:12,560 --> 00:01:15,570 So to do different operations. 14 00:01:15,620 --> 00:01:21,040 OK, let's start with talking about the actual things that interest us. 15 00:01:21,950 --> 00:01:28,730 So to do different operations on files, the first thing that we need is to create or better, I say, 16 00:01:28,730 --> 00:01:33,170 to declare a pointer of file type. 17 00:01:33,620 --> 00:01:35,160 That would be the first step. 18 00:01:35,990 --> 00:01:44,690 So similarly to the way we've created pointers of type int, for example, we use like this in Starp, 19 00:01:44,810 --> 00:01:52,640 OK, which was like a pointer called P, which is a pointer to end or basically like double star, I 20 00:01:52,640 --> 00:01:56,540 don't know, P two and so on and so forth. 21 00:01:56,930 --> 00:02:04,940 In a same way, in a very similar way, we are going to create a pointer of a file type, OK, something 22 00:02:04,940 --> 00:02:06,910 new but nothing to be afraid of. 23 00:02:07,100 --> 00:02:08,360 OK, just a different type. 24 00:02:09,080 --> 00:02:17,540 So just to give you some brief explanation, a file, OK, but we will create a pointer to a file type. 25 00:02:17,540 --> 00:02:26,300 These file is actually a struct that, let's say was designed to be used for working with files. 26 00:02:26,360 --> 00:02:33,680 OK, so it's really dedicated to working with files, as you probably already guessed by now. 27 00:02:33,990 --> 00:02:42,050 And these type of struct and a pointer to this struct will help us to work with files, read from them, 28 00:02:42,050 --> 00:02:44,050 write to them and so on and so forth. 29 00:02:44,060 --> 00:02:53,570 OK, you can see that the file struct is actually being defined in this SDD iodized H. 30 00:02:54,630 --> 00:03:03,360 And it is very similar to how you've defined and worked with different strokes, but basically it has 31 00:03:03,390 --> 00:03:08,520 been already created in some other library and now it is just being. 32 00:03:10,700 --> 00:03:17,150 Used in our program, so struct files struct, you've got the point. 33 00:03:18,020 --> 00:03:25,640 And now let us start talking about the basics index for working with files, so first of all, we said 34 00:03:25,640 --> 00:03:30,470 that we want to create a pointer, a pointer to a file. 35 00:03:30,830 --> 00:03:37,830 So how it will look like so file specified file start and let's go F.P. file pointer. 36 00:03:38,330 --> 00:03:42,260 So this step involves creating a pointer. 37 00:03:43,580 --> 00:03:53,870 That its name is F.P., right, an abbreviation for file pointer that points that points point to a 38 00:03:53,870 --> 00:03:55,220 file type. 39 00:03:55,830 --> 00:03:56,510 All right. 40 00:03:57,260 --> 00:04:02,030 And if it would like to take maybe a closer look at file, here is some strong. 41 00:04:02,130 --> 00:04:05,410 OK, I will not go into all the details here. 42 00:04:05,450 --> 00:04:12,200 OK, but there is much more thing we can talk about an hour or two, just about the files tracked and 43 00:04:12,200 --> 00:04:15,550 what it contains, what information it has and so on and so forth. 44 00:04:16,100 --> 00:04:18,410 So this will be like step number one. 45 00:04:18,560 --> 00:04:26,510 OK, so let's classify it as step number one, creating a pointer that holds that points to a file type. 46 00:04:27,080 --> 00:04:27,620 All right. 47 00:04:27,620 --> 00:04:28,610 It will look like this. 48 00:04:28,940 --> 00:04:30,530 OK, let me get it. 49 00:04:31,670 --> 00:04:32,380 Come here. 50 00:04:32,990 --> 00:04:33,530 Awesome. 51 00:04:34,640 --> 00:04:37,850 So now let's fix this also. 52 00:04:37,910 --> 00:04:45,220 Yeah, OK, so we've created these file and now we are going to see how we can open a file. 53 00:04:45,230 --> 00:04:48,530 So basically just having a pointer is not enough. 54 00:04:49,130 --> 00:04:56,660 OK, we need somehow to make this pointer to be associated with some file whether is going to read from 55 00:04:56,660 --> 00:05:03,470 these file or we are going to write these file, but we need to specify that this pointer will be associated 56 00:05:03,470 --> 00:05:03,820 with it. 57 00:05:04,340 --> 00:05:13,970 So step number two usually is going to be opening, giving access to a file and how it's going to be 58 00:05:13,970 --> 00:05:14,300 done. 59 00:05:15,320 --> 00:05:23,810 OK, so we will specify that we will work with F.P., will hold the address that will be returned by 60 00:05:23,810 --> 00:05:26,870 this function f open file open. 61 00:05:27,440 --> 00:05:29,390 And here we will specify two things. 62 00:05:29,840 --> 00:05:35,720 The first thing that we are going to specify, the first argument is going to be the file name. 63 00:05:36,050 --> 00:05:42,990 OK, it's just going to be some string specifying the actual name of the file. 64 00:05:43,460 --> 00:05:48,590 So if we want to read some file, we have to provide its exact name. 65 00:05:49,770 --> 00:05:55,950 So that's about reading from a file from, let's say, some existing file will need we will need to 66 00:05:55,950 --> 00:06:03,780 provide its exact name and if we would like to write to some file, then the string that we will use 67 00:06:03,780 --> 00:06:09,450 here will provide the name of the file to be created. 68 00:06:09,780 --> 00:06:15,630 OK, so if there is no file, we will need to specify the file name that we want to create. 69 00:06:16,630 --> 00:06:21,920 So this will be the first argument that we will use here and we can classify it like this, OK? 70 00:06:21,940 --> 00:06:23,860 Let me just right. 71 00:06:23,920 --> 00:06:25,570 The the structure itself. 72 00:06:25,570 --> 00:06:30,520 So it will be like ftf open and there will go like the file name. 73 00:06:31,150 --> 00:06:40,180 And afterwards we are going to specify as the second argument, the type of the operation type of operation. 74 00:06:41,470 --> 00:06:41,970 All right. 75 00:06:41,980 --> 00:06:44,890 So that's basically the the signature. 76 00:06:45,760 --> 00:06:55,720 And these type of operation is basically also a string that specifies what type of operation we want 77 00:06:55,720 --> 00:06:58,190 to make with this file. 78 00:06:58,450 --> 00:07:06,920 OK, so we said there will be like the file name and there will be the type of the operation on what 79 00:07:06,920 --> 00:07:17,110 point is this even type of operation even means basically it's used to specify in what way are you expecting 80 00:07:17,110 --> 00:07:25,270 your program to interact with a given file, whether it's going to be used for writing, reading or 81 00:07:25,270 --> 00:07:27,740 basically even for a pending mode. 82 00:07:28,180 --> 00:07:32,470 OK, so if you want to read from a file, specify the mode for reading. 83 00:07:32,470 --> 00:07:35,590 If you want to write to a file, specify a mode for writing. 84 00:07:35,860 --> 00:07:41,470 If you want to append something to an existing file, OK, to the end of the file, let's say, then 85 00:07:41,470 --> 00:07:42,520 use the append mode. 86 00:07:43,090 --> 00:07:48,600 Of course there are also additional modes, but I'm not going to discuss each and every one of them. 87 00:07:49,450 --> 00:07:59,440 I'm just going to give you, let's say, just the three most basic that will make you ready to use files. 88 00:07:59,620 --> 00:08:04,660 And the first one, the first, let's say here are types, types of operation. 89 00:08:05,260 --> 00:08:13,770 OK, so the first one is called W OK, and this is an abbreviation for writing mode. 90 00:08:14,320 --> 00:08:15,730 OK, that's a string. 91 00:08:15,730 --> 00:08:16,120 Right. 92 00:08:16,600 --> 00:08:17,530 We do recall. 93 00:08:17,530 --> 00:08:19,990 What is the difference between strings and Charas. 94 00:08:19,990 --> 00:08:20,230 Right. 95 00:08:20,260 --> 00:08:28,690 So by using this way, as far as the second argument, we are using a string in these double quotation 96 00:08:28,690 --> 00:08:37,750 marks and W is specified for writing, OK, this string is used to indicate the type of the operation 97 00:08:37,750 --> 00:08:40,600 for the file we will be working with. 98 00:08:42,110 --> 00:08:48,620 He's going to be writing, so we will open a file for writing. 99 00:08:49,130 --> 00:08:49,560 OK. 100 00:08:49,970 --> 00:08:56,370 The second type of operation is, as you've probably guessed by now, are for reading. 101 00:08:56,770 --> 00:09:04,820 OK, so this drawing indicates that the type of the operation for the file will be reading. 102 00:09:05,570 --> 00:09:10,080 We will be able to read the contents of the provided file. 103 00:09:10,490 --> 00:09:12,300 OK, if we use these type of 104 00:09:15,080 --> 00:09:22,160 operation and the last one, last but not least, OK, there are also additional ones that you can explore 105 00:09:22,160 --> 00:09:26,750 on your own, or basically I will cover up some of them in the future. 106 00:09:26,750 --> 00:09:32,690 But basically for now it's it's pretty much you have to understand writing, reading and spending. 107 00:09:32,970 --> 00:09:42,110 OK, so A will go for a landing mode and the string tells us that we can append information to the end 108 00:09:42,110 --> 00:09:42,780 of the file. 109 00:09:42,800 --> 00:09:45,620 OK, so if the file exists, what will happen to the end? 110 00:09:46,130 --> 00:09:51,260 If it does not exist, then probably a new file will be created. 111 00:09:51,860 --> 00:09:53,630 OK, and then we will be able to use it. 112 00:09:54,110 --> 00:09:59,720 So let's use some, I don't know, some example in this video or let's say let's give it in the next 113 00:09:59,720 --> 00:09:59,890 one. 114 00:09:59,900 --> 00:10:03,230 Just explain all the steps right here. 115 00:10:03,230 --> 00:10:11,600 And afterward, I will show you some example of real string for a file name and usage of some type operation 116 00:10:12,440 --> 00:10:13,960 with some nice example. 117 00:10:13,970 --> 00:10:17,090 So let's make it like to do complete. 118 00:10:19,130 --> 00:10:29,660 And what also I want to tell you is that these f open function that is being used is included in our. 119 00:10:30,680 --> 00:10:35,120 In our standard input output header file. 120 00:10:35,300 --> 00:10:39,180 OK, so this is a function somebody has written. 121 00:10:39,200 --> 00:10:45,940 OK, you can see it's each type in what it does, it returns a pointer to file. 122 00:10:45,950 --> 00:10:50,170 That's why we can assign it to FP and also come here. 123 00:10:50,810 --> 00:10:53,150 And also you see what it expects to receive. 124 00:10:53,150 --> 00:10:59,450 It expects to receive a file name and it expects to receive a mode, which is exactly just as I've shown 125 00:10:59,450 --> 00:11:00,130 you right now. 126 00:11:00,560 --> 00:11:11,420 So f open returns a pointer to a type file if the operation of opening the file has been completed successfully. 127 00:11:12,440 --> 00:11:18,470 Also, something that you need to understand is that not every time that you will try to open up a file, 128 00:11:18,500 --> 00:11:20,340 this will be done successfully. 129 00:11:20,690 --> 00:11:27,980 So if the operation of opening a file, whether it's for writing, reading and or appending he's going 130 00:11:27,980 --> 00:11:32,930 to fail, then these function f open is going to return null. 131 00:11:33,450 --> 00:11:40,190 If something went wrong and the operation of opening could not be accomplished successfully, then F 132 00:11:40,190 --> 00:11:41,750 Open is going to return now. 133 00:11:41,750 --> 00:11:48,620 And then you will have to like to check in to make sure if let's say FP does not equal to now, OK, 134 00:11:48,770 --> 00:11:54,290 then it means that the operation of opening the file was successful and you can start working with the 135 00:11:54,290 --> 00:11:59,150 file whether it's right into the file, read from the file or a band and so on. 136 00:12:00,440 --> 00:12:00,950 All right. 137 00:12:00,950 --> 00:12:01,350 So. 138 00:12:02,220 --> 00:12:02,640 Mm hmm. 139 00:12:03,440 --> 00:12:12,020 So this is used to make sure to make sure that the open operation was successful. 140 00:12:14,660 --> 00:12:21,380 And finally, finally, finally, once we are done working with our file, either it was for reading, 141 00:12:21,380 --> 00:12:21,950 writing. 142 00:12:21,950 --> 00:12:27,370 And so, one, we want to specify that we are a done working with these file. 143 00:12:27,830 --> 00:12:35,360 And as we've said, there are plenty of reasons to specify that we didn't say. 144 00:12:35,420 --> 00:12:42,680 Yeah, but for example, if you're working with a file, you're writing to it and you would like to 145 00:12:43,340 --> 00:12:49,760 basically to start reading from it from another process or another function or another, I don't know, 146 00:12:49,910 --> 00:12:50,990 some program. 147 00:12:51,710 --> 00:13:00,530 So it may be kind of hard went and it's a place for bugs when there is a stream of input writing to 148 00:13:00,530 --> 00:13:06,260 the file and there is a stream from another process reading from the file and basically what happens 149 00:13:06,260 --> 00:13:09,280 first or basically if someone else is writing this file. 150 00:13:09,710 --> 00:13:12,490 So this may be kind of problematic. 151 00:13:12,800 --> 00:13:13,310 So. 152 00:13:14,380 --> 00:13:21,820 For this, you would like to specify that whenever you are done working with a single file, just close 153 00:13:21,820 --> 00:13:29,930 it, close this stream, these direction of working with the file, specify that you want to start work 154 00:13:30,040 --> 00:13:33,700 to stop working with the file from this program. 155 00:13:33,750 --> 00:13:38,920 OK, so f close file, close FBI file pointer. 156 00:13:39,220 --> 00:13:44,860 Specify that for these programs you've written all the code relevant to working with the file. 157 00:13:44,870 --> 00:13:55,450 So some code for working with a file with the file and once you are done working with the file, simply 158 00:13:55,450 --> 00:13:57,730 specify f close F.P.. 159 00:13:58,210 --> 00:13:58,870 All right. 160 00:13:59,780 --> 00:14:08,210 Awesome, so just to go over the main steps required first step, creating a pointer of type of pointer 161 00:14:08,210 --> 00:14:15,240 to file, then opening your file based on the file name and the type of operation that you want to use. 162 00:14:15,410 --> 00:14:19,430 Step three, let's classify it like as step three. 163 00:14:19,580 --> 00:14:28,800 Step three, make sure the opening was successful. 164 00:14:28,820 --> 00:14:31,630 Make sure the situation successful. 165 00:14:31,970 --> 00:14:33,070 Yeah, that's right. 166 00:14:33,170 --> 00:14:46,700 And if I'm not wrong, step for step for work with the file, work with the file, reading, writing 167 00:14:47,630 --> 00:14:48,530 and so on. 168 00:14:49,700 --> 00:14:50,810 And final step. 169 00:14:50,810 --> 00:14:53,660 Don't forget this one step number five. 170 00:14:54,620 --> 00:14:58,520 Step number five, close the file. 171 00:15:00,910 --> 00:15:07,670 It doesn't mean like to close or delayed the filing, just means that stop this connection and maybe 172 00:15:07,670 --> 00:15:09,030 we will see also where it's. 173 00:15:09,940 --> 00:15:14,810 Actual problems, OK, like real problems may occur if you do not do so. 174 00:15:15,160 --> 00:15:21,610 So, yeah, I think there will be examples that I'm planning to show you this problem. 175 00:15:21,610 --> 00:15:24,120 But for now, you stopped working with the file. 176 00:15:24,130 --> 00:15:25,630 For example, you created a file. 177 00:15:25,630 --> 00:15:27,460 You wrote all the information to there. 178 00:15:28,060 --> 00:15:30,580 So stop it by using the F close. 179 00:15:30,940 --> 00:15:34,060 So just cut the link between your program and the file. 180 00:15:34,240 --> 00:15:40,420 So these file will be accessible and will allow working from different places. 181 00:15:40,730 --> 00:15:40,980 Okay. 182 00:15:42,280 --> 00:15:45,160 Oh, so basically nothing complicated. 183 00:15:45,190 --> 00:15:51,580 Guys, follow these steps and the next videos we are going to see some practical examples that will 184 00:15:51,580 --> 00:15:59,610 show you that files are actually kind of easy, fun and very useful. 185 00:16:00,130 --> 00:16:01,200 So my name is Vlad. 186 00:16:01,240 --> 00:16:02,200 This is Alphatech. 187 00:16:02,200 --> 00:16:03,460 Thank you so much for watching. 188 00:16:03,460 --> 00:16:07,960 And we will meet we'll see each other in the next videos by. 18819

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