I'm learning C language and I have a question about dynamic memory allocation.
Consider that I have a program that the user must enter numbers or typing the letter "E" to exit the program.
The numbers that the user enter must be stored in a one-dimensional array. This array begins with a single position.
How can I do to increase my array of integers to each number that the user enters to store this number in this new position? I think I must use pointers correct? And then, how do I print the values stored in the array?
All the examples I find are complex to understand for a beginner. I read about the malloc and realloc functions but I don't know exactly which one to use.
Can anyone help me? Thanks!
void main() {
int numbers[];
do {
allocate memory;
add the number to new position;
} while(user enter a number)
for (first element to last element)
print value;
}