So I'm trying to fill a char array with user input. However I do not want to specify the length of the array myself, thus limiting the user to the amount they can input. For example my code below will only allow the user to enter 5 characters and then will exit. Code in any language would be fine. (The below is C#).
Console.Write("Enter a number of characters of your choice...click 1 to exit: ");
bool exitCondition;
int counter = 0;
char[] character = new char[5];
do
{
exitCondition = false;
try
{
character[counter] = char.Parse(Console.ReadLine());
if (character[counter] == '1')
exitCondition = true;
}
catch (Exception ex)
{
Console.WriteLine("Error: {0}", ex.Message);
}
counter++;
}
while (exitCondition == false && counter < 5);
Code in any language would be fine.I think this may be to limit the bounds of code provided.