How to accept input from user until press ENTER in C?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to accept input from user until press ENTER in C??

My target: Write a program that let a user to input as many numbers as he wants, one at a time. Once, the user stops, print out the top 3 largest numbers and the average of all input. Now I use array to keep input to data but it has a problem that we don't know How many inputs that user will enter and if we declare array with large number memory like arr[50]; it will be a problem later.

6th Jul 2019, 10:41 AM
Pamica Srimora
Pamica Srimora - avatar
1 Answer
+ 1
Either ask user how many numbers will he input or tell him to enter something other than number to terminate input... You can't overwrite ENTER key functionality as far as I know And btw, user can enter numbers in form of NUMBER SPACE NUMBER SPACE, when cin sees space it automatically separates numbers and stores them separately in array
6th Jul 2019, 12:47 PM
Elva
Elva - avatar