I have been thinking about looping through arrays whose sizes are not fixed in advance... for example, allowing a user to input as many elements into an array as they want.
Question 1: How would I set up user prompts to enter as many elements of the array as they want? I am thinking a do-while loop, maybe with some sort of question as the while, such as:
#include <stdio.h>
#include <cs50.h>
int main(void)
{
int numbers[];
do
{
numbers[i] = get_int("Type an integer\n");
char more = get_char("Do you have another element to add? y/n \n");
}
while (more == y);
(I am pretty sure this code is not yet correct, but just some early thoughts...)
Question 2: If I wanted to get a variable (that I could then use as the limit of the number of times a for loop runs through that array) for the eventual size of that array, how would I do it, since the size of the array isn't determined until the user stops entering elements?
Thanks!