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 may help http://stackoverflow.com/questions/7898215/how-to-clear-input-buffer-in-c
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.
Join our real-time social learning platform and learn together with your friends!