Forum Discussion
Altera_Forum
Honored Contributor
12 years agohow to flush stdin buffer between two scanf?
Hi, I think this is a beginner-level question. Much appreciate your answers in advance! The following is my simple C-code: #include <stdio.h># include <string.h>
void main(void)
{
...
Altera_Forum
Honored Contributor
12 years agoAARGGGG cin/cout are an order of magnitude worse.
Not quite as bad as the stringstream classes though. Use fgets(buf, sizeof buf, stdin) to read a line and parse it yourself - in this case that just means that you need to allow for the trailinf '\n'. Lighter weight is to use read(0, buf, sizeof buf) - but that relies on the device drive code to generate lines (which it may not do).