How To Clear The Input Buffer | C Programming Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ม.ค. 2025

ความคิดเห็น • 63

  • @DarshJTech
    @DarshJTech 2 ปีที่แล้ว +33

    It feels that you're soon going to be the only person known to cover A-Z, of C programming on TH-cam... All the other channels miss one topic or the other!! KEEP MAKING SUCH MORE VIDEOS!! 🔥🔥

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +6

      Thank you for the enthusiastic feedback Darsh, I really appreciate it! :-) There are many, many more C videos I wish to make. Though in the long term, there are many other topics I wish to cover too.

  • @ABCD-6464
    @ABCD-6464 2 หลายเดือนก่อน

    This video is just perfect. no westing time, talks about the every possible scenario and gives solution for each of them while showcasing it perfectly. Best video ever.

  • @Raied114
    @Raied114 2 ปีที่แล้ว +11

    Your videos are getting me through my uni C course. You're a legend! Keep up the videos!

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +1

      Thank you for sharing this positive feedback Raed. And I'm so glad to hear the videos are helping you with your uni C course... helping students is the biggest reason why I love making these videos! :-)

  • @arthur_p_dent4282
    @arthur_p_dent4282 2 ปีที่แล้ว +4

    Just had to solve this one the other day. You are a treasure trove of useful c tips and tricks.

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +1

      Thank you for the kind feedback Arthur! :-)

  • @proggenius2024
    @proggenius2024 9 หลายเดือนก่อน +2

    thank you so much. I am always confused whenever I see fflush and now I understand even more.

  • @ning_nang
    @ning_nang ปีที่แล้ว +2

    You're a legend. My go to for C programming on youtube.

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +1

      Thank you for the kind feedback Jacob, I'm really glad these videos are your go to for C programming on TH-cam! :-D

  • @bettyswunghole3310
    @bettyswunghole3310 3 หลายเดือนก่อน

    Thanks for this! The lingering '
    ' after a scanf is one of the most annoying features of C!

  • @AnirudhSv-h8e
    @AnirudhSv-h8e หลายเดือนก่อน

    printf("Excellent explanation , to the point. Thank you.");

  • @nub8312
    @nub8312 ปีที่แล้ว +6

    I am studying computer science in Italy as an Italian and it makes me very sad when I come across situations like this. We are taught about the "input buffer", but our teachers simply tell us to use "fflush" without providing any explanation on how we can create our own version of this function. This lack of guidance and support is disheartening

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +4

      Sorry to hear that. :-( Often times in programming we're left learning things ourselves at the end of the day, so it's good you're seeking out other sources to learn from.

    • @nub8312
      @nub8312 ปีที่แล้ว +3

      yea, you are right :)

  • @fifaham
    @fifaham ปีที่แล้ว +3

    Very informative and to the point.

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +1

      I’m glad that you enjoyed it Firas! :-)

  • @AhmadAlMutawa_abunoor
    @AhmadAlMutawa_abunoor ปีที่แล้ว +1

    Thanks for referring me to this video. Much appreciated

  • @SSingh_here
    @SSingh_here 4 หลายเดือนก่อน

    As an Indian I never thought I'd have to watch any other nationals channel for learning programing, but since Ive discovered ur channel I mostly watch ur videos on topics I find hard to understand

  • @TechyBoy123
    @TechyBoy123 9 หลายเดือนก่อน

    you helped me so much and kept my brain braining, thank you

  • @rustergyt
    @rustergyt หลายเดือนก่อน +1

    Thanks! Subscribed + liked.

  • @gol.danime
    @gol.danime 6 หลายเดือนก่อน

    Hello, sptr = &S[i];
    23
    24 printf("Enter name: ");
    25 scanf("%[^
    ]s",sptr->name);
    I am having issue here when I use selective scanf then none of this input buffer works..what approach should I use? My program is regarding students information using structure array and accessing through structure pointer

  • @MarcoAurelio-sv2tk
    @MarcoAurelio-sv2tk 5 หลายเดือนก่อน

    The fflush() does not work in my compiler. Please remember that fgets() also include the
    in the string

  • @fadyasaad1105
    @fadyasaad1105 2 ปีที่แล้ว +1

    Thank you, That was my question 😊

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      Hahaha yes, your question inspired this video. :-)

  • @glimpse8144
    @glimpse8144 ปีที่แล้ว +1

    You can also use fseek() to clear input buffer.
    fseek(stdin, 0, SEEK_END);

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      Thanks so much for sharing this! I sort of prefer this method that you've shared, personally, because it's simpler. But just so people reading are aware, technically it's not 100% portable across C compilers. i.e. it's possible this statement will not work across all C compilers. See here: stackoverflow.com/a/16673023. That said, this method, as well as using fflush(stdin) are very widely supported in practice. :-)

    • @CarelessWinner
      @CarelessWinner ปีที่แล้ว

      Thank you. This worked for me in Visual Studio.
      "fflush(stdin);" seems to do nothing.
      "while ((c = getchar()) != '
      ') {}" creates and infinite loop requesting input.

  • @hasdrubal9799
    @hasdrubal9799 2 ปีที่แล้ว

    Tanks for another advance topic 😉

  • @edenng8431
    @edenng8431 2 ปีที่แล้ว +1

    Thank you. I always use while( getchar() != '
    ' ); to clear input buffer, but never include c != EOF. It is good to know.

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      You're welcome Eden, I'm glad you learned something new! :-)

  • @mohammadahmedragab837
    @mohammadahmedragab837 2 ปีที่แล้ว

    your videos are super clear easy and amazing, please make a video about cybersecurity 💚💙💙💙

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +1

      Thank you for the positive feedback! Hopefully one day I can cover cybersecurity, though it's a very big topic. :-)

  • @ГеоргийБелый-н7б
    @ГеоргийБелый-н7б ปีที่แล้ว

    Really nice, now i had tottaly understanded how its working
    Find your video while searching of alternative fflush(), Thanks!

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      You're welcome, I'm glad the video was able to help you out! :-)

  • @naboulsikhalid7763
    @naboulsikhalid7763 ปีที่แล้ว

    another great video that I added to my portfolio of solutions. if there Bigger than Thank you. Tell me what is it, and I will be glade to to send it back to you . Thanks a lot for helping us

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      Thank you for the support as always Naboulsi! :-)

  • @Rai_Te
    @Rai_Te ปีที่แล้ว

    Your program is an example for several things.
    #1 The C stdlib is not designed well ... this is a well known, and often discussed fact.
    #2 mixing fgets() with scanf() is usually a bad idea.
    better practise is to use fgets() to read a line from stdin, then
    parse this line using sscanf()
    #3 Do not forget to check returncodes from functions.

  • @yasinhamad5982
    @yasinhamad5982 6 หลายเดือนก่อน

    Thank you a lot sir

  • @arminhejazian5306
    @arminhejazian5306 8 วันที่ผ่านมา

    very interesting tnx

  • @soIatido
    @soIatido 2 ปีที่แล้ว

    I've just been thinking about this xd

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      Haha that's a funny coincidence! :-) I had a few people running into this problem in the comments of other videos so I decided to make this video.

  • @marcelijankowski9593
    @marcelijankowski9593 ปีที่แล้ว

    Thanks man!

  • @CZghost
    @CZghost 9 หลายเดือนก่อน

    Of course you can build a function that you can use repeatedly to flush the stdin.

  • @battarX
    @battarX 2 หลายเดือนก่อน

    Legend

  • @safeyamohamed3854
    @safeyamohamed3854 ปีที่แล้ว

    thank you so much

  • @RAHULRAWAT-cp5oc
    @RAHULRAWAT-cp5oc หลายเดือนก่อน

    thanks❤

  • @poisonmods
    @poisonmods 2 ปีที่แล้ว +1

    Good

  • @MrJzvoyeur
    @MrJzvoyeur 11 หลายเดือนก่อน

    why not just:
    while(getchar() != '
    ');

    • @yasinhamad5982
      @yasinhamad5982 6 หลายเดือนก่อน

      He wanted to make it simpler

  • @yoruichi5802
    @yoruichi5802 2 ปีที่แล้ว

    Nice