Ask your own question, for FREE!
Computer Science 15 Online
OpenStudy (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?

OpenStudy (misssunshinexxoxo):

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

OpenStudy (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.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Jalissa21: What does adenoma mea?
11 minutes ago 1 Reply 0 Medals
Twilightt: How Can We Prevent Gun Violence in American Schools?
2 hours ago 2 Replies 1 Medal
Twaylor: possible?
2 days ago 5 Replies 0 Medals
Arriyanalol: hekp
3 days ago 33 Replies 0 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!