• Curry
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?
Computer Science
  • Stacey Warren - Expert
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
  • katieb
I got my questions answered at in under 10 minutes. Go to now for free help!
  • misssunshinexxoxo
This may help
  • rsmith6559
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.

Looking for something else?

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