# Handling User Input in an Infinite Console Loop

DevFeed: [Handling User Input in an Infinite Console Loop](<https://devfeed.tech/articles/controlling-not-just-ctrl-c-32774.md>)

Original publisher: [Read original article](<https://reactos.org/blogs/controlling-not-just-ctrlc/>)

Published: 2016-08-13T00:00:00Z

Content type: tutorial

Language: en

Sources: [Front Page on ReactOS Website](<https://devfeed.tech/sources/front-page-on-reactos-website.md>)

Topics: [Code](<https://devfeed.tech/topics/code.md>), [console](<https://devfeed.tech/topics/console.md>), [ASCII](<https://devfeed.tech/topics/ascii.md>)

Tags: [ascii](<https://devfeed.tech/tags/ascii.md>), [blocking](<https://devfeed.tech/tags/blocking.md>), [code](<https://devfeed.tech/tags/code.md>), [console](<https://devfeed.tech/tags/console.md>), [free](<https://devfeed.tech/tags/free.md>), [loops](<https://devfeed.tech/tags/loops.md>), [open-source](<https://devfeed.tech/tags/open-source.md>), [os](<https://devfeed.tech/tags/os.md>), [react](<https://devfeed.tech/tags/react.md>), [reactos](<https://devfeed.tech/tags/reactos.md>), [win32](<https://devfeed.tech/tags/win32.md>), [winapi](<https://devfeed.tech/tags/winapi.md>)

## AI overview

This tutorial examines why a console application's infinite loop fails when it uses getchar() to detect a key press. The call blocks loop execution, so the article explores the need for non-blocking keyboard input while retaining controlled termination and final output.

## Source excerpt

Probably one of the funniest moments while developing is when you realize that something that "looks easy" is not as straight forward as it seemed at first sight. The task was "really easy": Just creating a console app which (1)loops infinitely, (2)doing some tasks and (3) which breaks when the user decides to stop it (4)printing some valuable info before exiting. "Naaah, this is easy. I just need a while/for/do-while/whatever infinite loop, a printf message asking the user to press a specific key to stop it, then a getch() to capture the key in order to break/stop the loop, and finally another printf to print the valuable info: PROFIT!