Curry
  • 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
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
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.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions

misssunshinexxoxo
  • misssunshinexxoxo
This may help http://stackoverflow.com/questions/7898215/how-to-clear-input-buffer-in-c
rsmith6559
  • 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.