Avoid This Common Scanf Mistake! [C Tutorial]

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ธ.ค. 2024
  • Want some guidance to help you learn how to code?
    📘Download my FREE 30 day coding challenge here:
    henrikmdev.com...
    Need 1-on-1 coaching?
    💻Click below to learn more about my mentoring program:
    henrikmdev.com...
    So there's this common ‘scanf’ or ‘getchar’ mistake that a lot of beginners make when first starting to learn how to code in C. These two C functions are common functions that beginners learn to handle basic user input for their programs. These mistakes are pretty understandable. Even I myself have made this mistake in the past, and I think it's even possible for senior developers to make this mistake too.
    I got some emails recently from a new C programmer, named Syed, asking me questions about the issues with his use of ‘scanf’ and ‘getchar’. He encountered this issue while he was going through my 30 Day Beginner Coding Challenge (Click the link above to download it for free!).
    The first program in that guide is a tip calculator program and he was having issues with the second time the program would run. This is a common mistake that I see people make when first starting to use ‘scanf’ and ‘getchar’ so I thought it would be helpful if I did a video about it going into it with a little more depth.
    In this video, you'll learn:
    ✅ how to debug code effectively
    ✅ another use case for why I like C
    ✅ how to use scanf with characters properly
    =================================================
    📚 Stay Tuned for More:
    If you found this video helpful, make sure to like and subscribe to our channel for more programming tutorials and tips. We have a lot more exciting content in store for you, so stay tuned!
    / @henrikmdev
    👨‍💻 Have Questions?
    If you have any questions or want to suggest topics for future videos, please leave a comment below. We love hearing from our viewers and are here to help!
    🔔 Turn on Notifications:
    Don't forget to ring the notification bell so you never miss an update from us. Stay ahead in your programming journey!
    =================================================
    💡 Coding Tutorials:
    • Coding tutorials
    💡 Git Tutorials:
    • Git tutorials
    💡 Dev Tool Tutorials:
    • Dev tools
    📁 Sample Code:
    Find the sample code used in our tutorials on our GitHub page:
    github.com/hen...
    =================================================
    📚 Books
    C Programming Language: amzn.to/4etzNE5
    Learning the bash Shell: amzn.to/483dvGN
    ⚙️ Gear
    Webcam - Logitec Brio: amzn.to/3zUqfTG
    Lighting - Ring Light Clip: amzn.to/3Y23yoj
    Microphone - AKG Pro Audio P220: amzn.to/40hunIf
    Audio Interface - Focusrite Scarlett 2i2: amzn.to/4gVTpSX
    Thank you for watching, and happy coding! 💻🧡
    -Henrik
    Disclaimer: Some of these links are referral links. I may earn a commission if you use them, at no extra cost to you. You're not obligated to use these links, but it would be appreciated. Thanks!
    #Programming #CodingMistakes #LearnToCode #CProgramming #ProgrammingTips #CodingChallenge #ASCIIValues #ProgrammingFoundations

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

  • @henrikmdev
    @henrikmdev  10 หลายเดือนก่อน

    Want some guidance to help you learn how to code?
    📘Download my FREE 30 day coding challenge here:
    henrikmdev.com/challenge

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

    Nice. I was having this issue thanks! 😀

    • @henrikmdev
      @henrikmdev  10 หลายเดือนก่อน

      Nice, glad it helped!

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

    I prefer using a loop to consume any characters left behind in the input stream buffer.
    while((c = getchar()) != '
    ' && c != EOF);

    • @henrikmdev
      @henrikmdev  10 หลายเดือนก่อน

      Yeah, that's one way of doing it! What about if the user enters some other white space characters other than
      like I did in my example?

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

      @@henrikmdev That loop will keep swallowing characters from the buffer until the new line is reached. If there is no new line in the buffer, then it will just keep swallowing until EOF is signaled.

    • @henrikmdev
      @henrikmdev  10 หลายเดือนก่อน

      Ahhh yeah, that's right!