File Access Basics | C Programming Tutorial

Поделиться
HTML-код
  • Опубликовано: 31 дек 2024

Комментарии •

  • @greateranimal
    @greateranimal Год назад +46

    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  Год назад +8

      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 8 месяцев назад

      Could u help me understand how to store and edit information in a file that's in like a table?

  • @gringotico1759
    @gringotico1759 2 года назад +41

    Great job. Way better that the top results on the topic. Much appreciated.

    • @PortfolioCourses
      @PortfolioCourses  2 года назад +5

      Thank you very much for the kind feedback! :-)

  • @NEKI01019
    @NEKI01019 Год назад +7

    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.

  • @luizg.5526
    @luizg.5526 10 месяцев назад +3

    For this 24min long video full of quality information, I just want to thank you!

  • @lazygamez7280
    @lazygamez7280 Год назад +1

    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

  • @tekamer6566
    @tekamer6566 Год назад +1

    Amazing that you still read the comments on these videos.
    God bless you for that

    • @PortfolioCourses
      @PortfolioCourses  Год назад +2

      Thank you! I love reading the comments, the people that watch these videos tend to be very supportive. :-)

  • @Cool-Linux-Penguin
    @Cool-Linux-Penguin 6 месяцев назад

    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!

  • @llynxfyre
    @llynxfyre 2 года назад +14

    Thanks for this! Really clear and easy to understand.

    • @PortfolioCourses
      @PortfolioCourses  2 года назад +2

      You're welcome! I'm glad to hear you found it clear and easy to understand. :-D

  • @steevenkenny9791
    @steevenkenny9791 2 года назад +3

    The explanation is crystal clear... great job sir...

  • @mohrezshaikh4091
    @mohrezshaikh4091 8 дней назад

    there is a course on Udemy that costs about 3000/4000 rupees and this playlist is way better than that course
    well done! and thanks a lot!

  • @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! :-)

  • @firepower01
    @firepower01 2 года назад +9

    This is an awesome tutorial man, thanks a lot.

  • @justcurious1940
    @justcurious1940 Год назад +1

    Thank u DR kevin, your tutorials are the best.

    • @PortfolioCourses
      @PortfolioCourses  Год назад

      You’re welcome, I’m glad you enjoy the tutorials! :-)

  • @rfdave3980
    @rfdave3980 Год назад +2

    Nothing better than C.

  • @ellismail7196
    @ellismail7196 Год назад +5

    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 Год назад +2

      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 !!

  • @mro7432
    @mro7432 2 года назад +2

    very helpful video man ngl, thanks for sharing this knowledge for free

  • @uberblarrf
    @uberblarrf Год назад

    best tutorials on youtube, thank you so much 🙂

    • @PortfolioCourses
      @PortfolioCourses  Год назад

      You're very welcome, and thank you for the kind feedback! :-)

  • @hyperphenomenal4360
    @hyperphenomenal4360 Год назад

    to the point and excellent explanation, your videos are treasure trove

  • @dharmik023
    @dharmik023 9 месяцев назад +1

    Literally 🥶 your video is so amazing and useful for college students!

  • @edwardmalegale230
    @edwardmalegale230 2 года назад

    You saved my technical interview ☺

    • @PortfolioCourses
      @PortfolioCourses  2 года назад +1

      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! :-)

  • @eighteen7875
    @eighteen7875 2 года назад +1

    Thanks bro! Always helping

    • @PortfolioCourses
      @PortfolioCourses  2 года назад

      You’re welcome! Thanks for all the encouraging feedback.

  • @yusufetturki
    @yusufetturki 2 года назад +1

    its really good explanation and tutorial
    thanks.

  • @ecro5236
    @ecro5236 3 года назад +1

    Thanks for this great tutorial!

  • @jakke1975
    @jakke1975 3 месяца назад

    do you also have a tutorial on open instead of fopen? i'm starting with the basics... taking steps before i run

  • @ABDELMUNIEMOMARSULIMANAHMEDTEE

    nice explanation, I really appreciate this.

    • @PortfolioCourses
      @PortfolioCourses  Год назад

      You're welcome Abdelmuniem, I'm glad you enjoyed the explanation! :-)

  • @juniorrokudevelopertutoria3734
    @juniorrokudevelopertutoria3734 4 месяца назад

    Great video!

  • @idanmariani8601
    @idanmariani8601 2 года назад

    awsome video like allways best explain ever..thank you for all the hard work you put to help us..
    your awsome.. :)

    • @PortfolioCourses
      @PortfolioCourses  2 года назад

      You're welcome Idan I'm glad you enjoyed the explanation, and thank you for the very positive and encouraging feedback too. :-)

  • @lradhakrishnarao902
    @lradhakrishnarao902 2 года назад +2

    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  2 года назад +11

      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.

  • @nix4254
    @nix4254 28 дней назад +1

    the GOAT

  • @barkotzeyohannes4104
    @barkotzeyohannes4104 2 года назад

    I wish you were my professor!!

    • @PortfolioCourses
      @PortfolioCourses  2 года назад

      Aww thanks Barkot that is such nice positive feedback and it means a lot to me! :-)

  • @dailyjihad8396
    @dailyjihad8396 2 года назад +1

    That's really helpful , thanks alot

  • @Maik.iptoux
    @Maik.iptoux 11 месяцев назад

    What is when my input file had a unknow size of lines? But i wan't to have all in the buffer?

    • @PortfolioCourses
      @PortfolioCourses  11 месяцев назад +1

      You might find this video interesting if I’m understand what you are asking correctly: ruclips.net/video/Oa_ji3dDFew/видео.htmlsi=ZOfk9MAH--lfCKV1

    • @PortfolioCourses
      @PortfolioCourses  11 месяцев назад +1

      And this video may be of interest too: ruclips.net/video/vQno9S3yF80/видео.htmlsi=rnRtjymSMC5jjI2F

  • @ionguzun3952
    @ionguzun3952 2 года назад +2

    can you please do a video about files and structures in c

  • @DiogoGaming2
    @DiogoGaming2 Год назад +1

    This video is a big "W"

  • @stevejokes2182
    @stevejokes2182 2 года назад +1

    How to generate all output in terminal into .dat file?

    • @PortfolioCourses
      @PortfolioCourses  2 года назад +1

      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?

  • @smadi0x86
    @smadi0x86 2 года назад

    hello!, what if I want to read a second number on the same line seperated by a space from the first

    • @PortfolioCourses
      @PortfolioCourses  2 года назад +1

      Great question Saud! :-) You could do something like this:
      fscanf(file, "%f %f", &dblvar1, &dblvar2);
      You might find this related video interesting: ruclips.net/video/Gaq10GBlRJA/видео.html

  • @khomo12
    @khomo12 5 месяцев назад

    Thank you!

  • @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).

  • @yogeshchauhan9401
    @yogeshchauhan9401 Год назад +1

    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: ruclips.net/video/Ui0idK9Dh04/видео.html

  • @creatively1208
    @creatively1208 7 месяцев назад

    you are the goat

  • @mohammadmousavi6046
    @mohammadmousavi6046 2 года назад +1

    thanks for video ! 😉😉🧡🧡🧡🧡 , please create new course for advanced c and using c in real project

    • @PortfolioCourses
      @PortfolioCourses  2 года назад

      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.

  • @iGavid_Doggins
    @iGavid_Doggins 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....

    • @iGavid_Doggins
      @iGavid_Doggins 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.

    • @iGavid_Doggins
      @iGavid_Doggins 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 года назад +1

      @@iGavid_Doggins 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!

  • @saifUllah-q4e1c
    @saifUllah-q4e1c 3 месяца назад

    thank you

  • @tokuumeiii8792
    @tokuumeiii8792 9 месяцев назад

    it doesn't work on codeblocks doesn'it ?

  • @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. :-)

  • @CodyHoskin
    @CodyHoskin 3 года назад +1

    How do I extract a float number from a text file? lol

    • @PortfolioCourses
      @PortfolioCourses  3 года назад

      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

  • @paganimarker1898
    @paganimarker1898 2 года назад

    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  2 года назад +3

      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(): ruclips.net/video/8RucxSeAemw/видео.html. The other thing we can do with exit is setup functions to run when the program exists, this video covers that topic: ruclips.net/video/Ik3nzpn5LoE/видео.html. Hopefully this helps! :-)

    • @paganimarker1898
      @paganimarker1898 Год назад

      @@PortfolioCourses wow, thank you !

    • @PortfolioCourses
      @PortfolioCourses  Год назад

      @@paganimarker1898 You're welcome! 🙂

  • @preciouslife1212
    @preciouslife1212 Год назад

    thank you so much

  • @wambateufack
    @wambateufack 4 месяца назад

    Thanks sir

  • @paganimarker1898
    @paganimarker1898 2 года назад

    is "w" the only way to create file?

    • @PortfolioCourses
      @PortfolioCourses  2 года назад +1

      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 2 года назад +1

      @@PortfolioCourses Thank you

    • @PortfolioCourses
      @PortfolioCourses  2 года назад +1

      You're welcome! :-)

  • @vinamrgroverDemontutorials
    @vinamrgroverDemontutorials 2 года назад

    underrated channel (^_^)

  • @davidwesh4123
    @davidwesh4123 Год назад

    Good

  • @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  Год назад +1

      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: ruclips.net/video/CzAgM5bez-g/видео.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  Год назад +1

      @@emanuel_ramaci Awesome, and you're welcome! 🙂

  • @l0gi550
    @l0gi550 Год назад +1

    This is a great tutorial, thanks!

  • @farhanishraq5812
    @farhanishraq5812 Год назад

    thank u so much

    • @PortfolioCourses
      @PortfolioCourses  Год назад +1

      You're welcome, I'm glad you enjoyed the video! :-)