A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing


  • one year ago

I have a question about this block of code. It's a clear buffer function in C. By setting character equal to getchar(), doesn't getchar() just wait for another user input? How exactly does this clear the buffer, can someone walk me through it?

  • This Question is Closed
  1. misssunshinexxoxo
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    This may help http://stackoverflow.com/questions/7898215/how-to-clear-input-buffer-in-c

  2. rsmith6559
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 2

    That code does have some issues. First, the function is being given a single character, which it believes is an int. ints are usually either 4 or 8 bytes, characters are usually one. The likelihood of a four byte value equalling 0x0a are slim. Even if that function runs, it's not going to leave a clear buffer. It would stop working leaving '\n' in the buffer. Plus, just for fun, strings in C are delimited by a '\0' byte.

  3. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...


  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.