<p>What's the best way to get user input in a C program where the choices are of a limited number?</p>
<p>Say for example the choices are:</p>
<p>A) Print the list.
B) Add 99 to the end of the list.
C) Delete all duplicates.
5) Reset 5 times.</p>
<p>Entering &quot;A&quot; and then Enter is OK.
Or, just a single keystroke would work as well.</p>

[{'answer_id': 42704, 'author': 'David Bryson', 'author_id': 3663, 'author_profile': 'https://Stackoverflow.com/users/3663', 'pm_score': 0, 'selected': False, 'text': "<p>I have used something simple like the following:</p>\n<pre><code>int intput()\n{\n    char input = 0;\n    int ret_val = 0;\n\n    read(0, &amp;input, 1);\n\n    switch(input) {\n        case 'c':\n            // Do c\n            break;\n\n        case 'p':\n            // Do p\n            break;\n\n        case 'd':\n            // Do d\n            break;\n\n        case 'q':\n            quit = 1;\n            break;\n\n        case '?':\n            PRINT(ENABLE, &quot;c - connect\\n&quot;);\n            PRINT(ENABLE, &quot;p - ping\\n&quot;);\n            PRINT(ENABLE, &quot;d - disconnect\\n&quot;);\n            PRINT(ENABLE, &quot;q - quit\\n&quot;);\n            PRINT(ENABLE, &quot;? - this message\\n&quot;);\n            break;\n    }\n\n    return 0;\n}\n</code></pre>\n"}, {'answer_id': 43527, 'author': 'Tim Ring', 'author_id': 3685, 'author_profile': 'https://Stackoverflow.com/users/3685', 'pm_score': 0, 'selected': False, 'text': "<p>Instead of using</p>\n<pre><code>switch(input)\n</code></pre>\n<p>use...</p>\n<pre><code>switch (toupper(input))\n{\n    case 'A':\n</code></pre>\n<p>This will allow the user to enter 'a' or 'A' and saves you having to check for upper and lower case.</p>\n"}, {'answer_id': 48627, 'author': 'dmityugov', 'author_id': 3232, 'author_profile': 'https://Stackoverflow.com/users/3232', 'pm_score': 3, 'selected': True, 'text': '<p><code>getchar()</code>, or <code>cgetc()</code>, depending on the platform</p>\n'}]
['https://Stackoverflow.com/questions/42693', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3807/']