File Access Basics | C Programming Tutorial

  Рет қаралды 89,192

Portfolio Courses

Portfolio Courses

3 жыл бұрын

An introduction to file access I/O in C. Source code: github.com/portfoliocourses/c.... Check out www.portfoliocourses.com to build a portfolio that will impress employers!

Пікірлер: 105
@gringotico1759
@gringotico1759 Жыл бұрын
Great job. Way better that the top results on the topic. Much appreciated.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thank you very much for the kind feedback! :-)
@greateranimal
@greateranimal Жыл бұрын
I've really appreciated the videos you've made on C programming. College did not leave me with a very strong grasp of lower level programming languages like C and so I've been going through all your videos on C programming; they have been an absolute treasure trove. Unlike other tutorials, you make it a point to explain all the standard functions that are at your disposal and how you may want to use them in different circumstances, and you also make it a point to explain why you are doing what you are doing when it comes to manual memory management. You're a legend 💪🏽
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thank you very much for sharing this kind feedback with me, it's very encouraging for me to hear that these videos are helping you out and that you're enjoying the teaching style. :-D
@Flaxxeed
@Flaxxeed 3 ай бұрын
Could u help me understand how to store and edit information in a file that's in like a table?
@NEKI01019
@NEKI01019 8 ай бұрын
The best C programming tutorial series ever! I feel so satisfied that I now know everything you taught. For the starters to C, I highly recommend to follow the whole playlist.
@lazygamez7280
@lazygamez7280 7 ай бұрын
I am 100% sure when saying this that you got some of the best, most high quality content right here. In school they didnt explain files very well and this video did it in 20 minutes. Thank you so much
@luizg.5526
@luizg.5526 5 ай бұрын
For this 24min long video full of quality information, I just want to thank you!
@PortfolioCourses
@PortfolioCourses 5 ай бұрын
You're very welcome! :-)
@llynxfyremusic
@llynxfyremusic 2 жыл бұрын
Thanks for this! Really clear and easy to understand.
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You're welcome! I'm glad to hear you found it clear and easy to understand. :-D
@firepower01
@firepower01 2 жыл бұрын
This is an awesome tutorial man, thanks a lot.
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You're welcome! 😀
@Cool-Linux-Penguin
@Cool-Linux-Penguin Ай бұрын
This was very helpful, thank you so much! Also I know it's 2 year's old but this video is rock solid and the instruction's and explaination's are great!
@hyperphenomenal4360
@hyperphenomenal4360 9 ай бұрын
to the point and excellent explanation, your videos are treasure trove
@l0gi550
@l0gi550 Жыл бұрын
This is a great tutorial, thanks!
@steevenkenny9791
@steevenkenny9791 Жыл бұрын
The explanation is crystal clear... great job sir...
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thank you, I'm glad you enjoyed it! :-)
@justcurious1940
@justcurious1940 Жыл бұрын
Thank u DR kevin, your tutorials are the best.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You’re welcome, I’m glad you enjoy the tutorials! :-)
@tekamer6566
@tekamer6566 Жыл бұрын
Amazing that you still read the comments on these videos. God bless you for that
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thank you! I love reading the comments, the people that watch these videos tend to be very supportive. :-)
@okibeogomola5921
@okibeogomola5921 Жыл бұрын
before watching your videos , I click like because I know for sure its going to be great, keep up the great content sir.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I'm so glad to hear you're enjoying the content, and thank you for the support Okibe! :-)
@ecro5236
@ecro5236 2 жыл бұрын
Thanks for this great tutorial!
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You're welcome! :-D
@uberblarrf
@uberblarrf Жыл бұрын
best tutorials on youtube, thank you so much 🙂
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're very welcome, and thank you for the kind feedback! :-)
@mro7432
@mro7432 Жыл бұрын
very helpful video man ngl, thanks for sharing this knowledge for free
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome! 🙂
@eighteen7875
@eighteen7875 2 жыл бұрын
Thanks bro! Always helping
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You’re welcome! Thanks for all the encouraging feedback.
@ABDELMUNIEMOMARSULIMANAHMEDTEE
@ABDELMUNIEMOMARSULIMANAHMEDTEE Жыл бұрын
nice explanation, I really appreciate this.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome Abdelmuniem, I'm glad you enjoyed the explanation! :-)
@idanmariani8601
@idanmariani8601 Жыл бұрын
awsome video like allways best explain ever..thank you for all the hard work you put to help us.. your awsome.. :)
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome Idan I'm glad you enjoyed the explanation, and thank you for the very positive and encouraging feedback too. :-)
@edwardmalegale230
@edwardmalegale230 Жыл бұрын
You saved my technical interview ☺
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I’m glad to hear this helped you Edward, and I hope you get the job! :-)
@darrenli2526
@darrenli2526 Жыл бұрын
thank you so much, you saved my assignment
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You’re very welcome, and good luck on the assignment! :-)
@dailyjihad8396
@dailyjihad8396 2 жыл бұрын
That's really helpful , thanks alot
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You're welcome! 😀
@dharmik023
@dharmik023 4 ай бұрын
Literally 🥶 your video is so amazing and useful for college students!
@yusufetturki
@yusufetturki 2 жыл бұрын
its really good explanation and tutorial thanks.
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You’re welcome Yusuf! :-)
@ellismail7196
@ellismail7196 Жыл бұрын
i really appreciae your effort, and i like the way you explain things and make it easier and smooth, but i've a question that popped up in to my mind, why either fgets or fscanf get into the new line just by using while without doing increment to the new line !
@justcurious1940
@justcurious1940 Жыл бұрын
I think it's because of the file position indicator inside our object of the type FILE , I know it may sound complicated but it's not !! when we say FILE *object = fopen("x.txt","r") ; we are actually creating a variable(object) of type struct and inside this struct there is variable that changes each time we call fgets or fgetc .. notice every time we call those function we are passing our object of of FILE(struct) type as pointer so changes will apply and remain in our main object, maybe my explanation is not totally accurate because object is a pointer of type FILE but I think the logic of it is like that. the question that popped up into my mind is how is it possible write to a txt file the same way u write to the console, it's strange to me and it does not make sense but I did some researches and people are saying that everything in our computers is files,what the F**k they mean by that , it does not make any sense , it does not make any sense because our brains get mess up with too much abstraction from windows,I think an operating system course is needed to understand these topics so yea I'm going to take one, sorry if I wasted your time !!
@khomo12
@khomo12 Күн бұрын
Thank you!
@creatively1208
@creatively1208 2 ай бұрын
you are the goat
@farhanishraq5812
@farhanishraq5812 Жыл бұрын
thank u so much
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome, I'm glad you enjoyed the video! :-)
@smadi0x86
@smadi0x86 Жыл бұрын
hello!, what if I want to read a second number on the same line seperated by a space from the first
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Great question Saud! :-) You could do something like this: fscanf(file, "%f %f", &dblvar1, &dblvar2); You might find this related video interesting: kzfaq.info/get/bejne/fcehZJN4p9K2enU.html
@rfdave3980
@rfdave3980 Жыл бұрын
Nothing better than C.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I agree. :-)
@ሰውመሆን
@ሰውመሆን Жыл бұрын
thank you so much
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're very welcome Robel! :-)
@krishnabhagavankarri5623
@krishnabhagavankarri5623 Жыл бұрын
Which command-line interface are you using,sir? I can't use 'touch',vi commands in my windows 11 terminal or command prompt. What do I have to do...?😒
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Great question Krishna! :-) I am using Terminal on Mac OS, which is a "bash shell", a type of shell that is used in Unix-like systems like Linux and Mac OS. A Windows shell is different and does not support the same commands. So something like 'touch' will not work on Windows. You could use a text editor instead to create a file and open it though. In many situations Windows will have a command that allow us to do 'the equivalent' of what we can do with a Terminal command: stackoverflow.com/a/37756874. It's also possible to get a Linux shell on Windows using things like Windows Subsystem for Linux, but that can be a fair bit of work and would be challenging for new beginners I think (though it may be a good learning experience).
@barkotzeyohannes4104
@barkotzeyohannes4104 Жыл бұрын
I wish you were my professor!!
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Aww thanks Barkot that is such nice positive feedback and it means a lot to me! :-)
@BalaSubramanian-rw4js
@BalaSubramanian-rw4js Жыл бұрын
Can you tell what compiler you are using
@PortfolioCourses
@PortfolioCourses Жыл бұрын
In this video I am using Visual Studio Code as a text editor and the gcc compiler with the terminal on a Mac. :-)
@stevejokes2182
@stevejokes2182 2 жыл бұрын
How to generate all output in terminal into .dat file?
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Great question Steve. 🙂 Where is the output in the terminal coming form? Is it text that the user is typing in? Or is it output from the program that is running?
@ionguzun3952
@ionguzun3952 2 жыл бұрын
can you please do a video about files and structures in c
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Like reading data from a file into a struct?
@lradhakrishnarao902
@lradhakrishnarao902 Жыл бұрын
There's only one thing missing. Why do we need to use file, and what benefits they offer . Because, this is usually asked in the interview questions.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Great question! :-) Basically, if we store data into variables, the data will disappear when our program stops execution. Storing data into a file allows us to retrieve the data later, even if we restart our program, or even our computer. Storing data into a file also allows us to make copies of the file, and share the file with others.
@Maik.iptoux
@Maik.iptoux 7 ай бұрын
What is when my input file had a unknow size of lines? But i wan't to have all in the buffer?
@PortfolioCourses
@PortfolioCourses 6 ай бұрын
You might find this video interesting if I’m understand what you are asking correctly: kzfaq.info/get/bejne/hcePncxkyaqqlas.htmlsi=ZOfk9MAH--lfCKV1
@PortfolioCourses
@PortfolioCourses 6 ай бұрын
And this video may be of interest too: kzfaq.info/get/bejne/rLeeopyEmN-qaGQ.htmlsi=rnRtjymSMC5jjI2F
@vinamrgroverDemontutorials
@vinamrgroverDemontutorials 2 жыл бұрын
underrated channel (^_^)
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Thank you Vinamr! :-D
@mohammadmousavi6046
@mohammadmousavi6046 Жыл бұрын
thanks for video ! 😉😉🧡🧡🧡🧡 , please create new course for advanced c and using c in real project
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome Mohammad! 🙂 Maybe one day I can create a course on advanced C, but I think a course on advanced C would probably be many courses covering different subtopics like threads, networking, etc.
@paganimarker1898
@paganimarker1898 Жыл бұрын
I want to ask what is the meaning of exit(1)/exit(-1) FILE *pd; if((pd = fopen("test","w")) == NULL) { puts("Can`t be done."); exit(-1); } Is the same as return 0/1; ??
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Great question Pagani! :-) When we call exit() the program will exit, and the argument we provide to exit() will be the status code. If we have exit(0) the program will exit with status code 0, which is considered 'success'. If we have exit(1) or exit(-1) the program will exit with status code 1 or -1, both of which are considered 'error' (any non-zero exit status code is considered 'error'). When we use return 0 in main the program will exit with status 0, and if we use return 1 in main the program will exit with status 1. But we can only use return to exit the program in main. If we want to exit the program in other functions, we can use exit instead. So that's the biggest difference.... with exit we can exit the program in any function. This video covers exit(): kzfaq.info/get/bejne/brilltuEyqfJnas.html. The other thing we can do with exit is setup functions to run when the program exists, this video covers that topic: kzfaq.info/get/bejne/f9Fjod2h05uwn3k.html. Hopefully this helps! :-)
@paganimarker1898
@paganimarker1898 Жыл бұрын
@@PortfolioCourses wow, thank you !
@PortfolioCourses
@PortfolioCourses Жыл бұрын
@@paganimarker1898 You're welcome! 🙂
@CodyHoskin
@CodyHoskin 2 жыл бұрын
How do I extract a float number from a text file? lol
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Maybe I'll make a video on this soon! In the meantime, this answer here is pretty good, you basically can use fscanf() with %f and %lf to read in floats and doubles from a file: stackoverflow.com/a/7152018
@DaRza17
@DaRza17 2 жыл бұрын
I need some help please, I'm trying to read integers from a .txt file and add them together. The problem is the file also contains letters, kinda like this: Peter 20 Frank 30 Joe 40.... I want to ignore letters completely and just add the numbers together, too tricky for me....
@DaRza17
@DaRza17 2 жыл бұрын
Some additional info, the way I wrote to the file was: fprintf(fp, "Peter %d ", userNames(varOne));
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
So there isn't really a super easy answer to this question, it's a bit tricky. There are a few ways you could do it. :-) You could read each entire line into a string (char array) and then use strtok() to pull out the integer you're interested in. These examples might help with that approach, the link to the video tutorial is at the top of the file in the comments: github.com/portfoliocourses/c-example-code/blob/main/file_lines_to_string_array.c github.com/portfoliocourses/c-example-code/blob/main/strtok.c Another way to do it would be closer to the way this 'read from CSV file' example uses fscanf(), again the link to the video is at the top of the file: github.com/portfoliocourses/c-example-code/blob/main/csv_to_struct_array.c So at the bottom of that code there is a loop that uses fscanf() to read the data from the file. If you had variables: char name[2048]; int number; You could then have fscanf: fscanf(file,%2048[^0123456789]%d ",name,&number); To read in each number, in a similar way to that example. You would then have to add the numbers together.
@DaRza17
@DaRza17 2 жыл бұрын
@@PortfolioCourses Wow thanks dude, I'm gonna go through all of this step by step. There is so much to learn😮... I remember someone saying "C is easy and beginner friendly, it only has 32 keywords". 🤣 By the way your content is absolutely GREAT.🏆🥇🏆
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
@@DaRza17 Oh wow haha I would say C is one of the less forgiving languages, especially compared to something like Python. 🙂 And thank you for the kind words I'm glad to hear you enjoy the content!
@davidwesh4123
@davidwesh4123 Жыл бұрын
Good
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thank you David! :-)
@tokuumeiii8792
@tokuumeiii8792 4 ай бұрын
it doesn't work on codeblocks doesn'it ?
@yogeshchauhan9401
@yogeshchauhan9401 Жыл бұрын
Can u explain feof function?
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Basically the feof() function returns true when we reach the end of a file, and false otherwise. This explains more: www.tutorialspoint.com/c_standard_library/c_function_feof.htm. I may try to make a video on feof() specifically though, that might be something people would be interested in. :-)
@yogeshchauhan9401
@yogeshchauhan9401 Жыл бұрын
@@PortfolioCourses thanks for the response.Can u see this statement is this correct? It's important to note that feof only tells you if you've reached the end of the file after you've tried to read past it.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I believe that statement is correct, yes. :-)
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Here you go, a new video on the feof() function: kzfaq.info/get/bejne/i89gnMd8nqrMYGg.html
@paganimarker1898
@paganimarker1898 Жыл бұрын
is "w" the only way to create file?
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Great question Pagani! :-) We could use "a" for append and that will also create the file if it doesn't exist. This article does a good job talking about the different access modes: www.geeksforgeeks.org/basics-file-handling-c/.
@paganimarker1898
@paganimarker1898 Жыл бұрын
@@PortfolioCourses Thank you
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome! :-)
@DiogoGaming2
@DiogoGaming2 Жыл бұрын
This video is a big "W"
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I’m glad you enjoyed it! :-)
@emanuel_ramaci
@emanuel_ramaci Жыл бұрын
why fgets() read only first line of "in.txt" ? because in "in.txt" i wrote more than one line by sending a new line. thank you!!
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Great question Emanuel! :-) Though the answer is essentially.... because that's how fgets() works. It stops at the first newline it encounters. If you want to read all the file contents into a string this video might help with that: kzfaq.info/get/bejne/eeBxmrBmx8veXZs.html.
@emanuel_ramaci
@emanuel_ramaci Жыл бұрын
@@PortfolioCourses i just watched the video and it's great the way you explain it, thank you very much!!
@PortfolioCourses
@PortfolioCourses Жыл бұрын
@@emanuel_ramaci Awesome, and you're welcome! 🙂
Command Line Arguments | C Programming Tutorial
6:36
Portfolio Courses
Рет қаралды 55 М.
Binary File Access Introduction | C Programming Example
16:17
Portfolio Courses
Рет қаралды 25 М.
Я обещал подарить ему самокат!
01:00
Vlad Samokatchik
Рет қаралды 9 МЛН
Survive 100 Days In Nuclear Bunker, Win $500,000
32:21
MrBeast
Рет қаралды 85 МЛН
struct Basics | C Programming Tutorial
24:44
Portfolio Courses
Рет қаралды 134 М.
String In Char Array VS. Pointer To String Literal | C Programming Tutorial
9:58
The Art of Code - Dylan Beattie
1:00:49
NDC Conferences
Рет қаралды 4,7 МЛН
Reading and Writing Files in C, two ways (fopen vs. open)
7:07
Jacob Sorber
Рет қаралды 99 М.
Why The Windows Phone Failed
24:08
Apple Explained
Рет қаралды 190 М.
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Рет қаралды 2,1 МЛН
Read And Write An Array Of Structs To A Binary File | C Programming Example
18:27
Reading/Writing structs to files (aka Serialization)
14:41
CodeVault
Рет қаралды 74 М.
Linux File System/Structure Explained!
15:59
DorianDotSlash
Рет қаралды 4,1 МЛН
Será Que a FITA vai Grudar ela na PAREDE😱 #shorts
0:44
Lucan Pevidor
Рет қаралды 66 МЛН
Draw your favorite | Inside Out Graffitis
0:30
AmogusMan
Рет қаралды 20 МЛН
Amazing tools #shorts
0:35
SA VA
Рет қаралды 7 МЛН
РЫБАЛКА ДОМА
0:17
KINO KAIF
Рет қаралды 18 МЛН
ПАЛОЧКИ + БУТЫЛКА = ВАЗА😳🥢
0:52
polya_tut
Рет қаралды 3,8 МЛН