Read characters until a newline or EOF is reached:
ch = getchar();
while (ch != '\n' && ch != EOF);
This is the only portable method, but it also has a downside of blocking for input if the stream is already empty when the loop starts. Unfortunately, there's no way to get around that without breaking portability.