First your loop should not be infinite if you are reading values for the array "n", which has 30 positions, this should be the size/duration/number of interactions of your loop.
Some considerations:
- If you declare an array with X positions, it makes no sense to read "part" of it and exit in the middle using the
break
, would be better to use a dynamic array, but most likely by your code and knowledge that apparently you have, it’s not what you need. For an array in c
, use an array with defined size, unless it is extraordinarily necessary to do something different;
- To conditions where we don’t know the number of interactions but only the stopping condition, it is better to use for example
while
. So in the first code the for (;;)
could be while (n != 7)
, to exemplify;
- Answering your question, to list the values just repeat the same loop below and show the values. This as an exercise, because if you just want to show, it can be in the same loop;
Let’s assume that the value 30, which you have in your condition is the limit of your loop, IE, you want to enter with 30 values, could do so (answering your question "I don’t know what’s inside "for(xxxxxx)":
int totalDeNumeros = 30;
int n[totalDeNumeros];
for (int i=0;i< totalDeNumeros;i++)
{
printf("Digite um numero inteiro: ");
scanf("%d", &n[i]);
}
printf("Numeros digitados:\n");
for (int i=0;i< totalDeNumeros;i++)
{
printf("%d\n",n[i]);
}
About a dynamic array, have another question related to code example to realize that it is much more complex to implement: How to write a loop to read a file to a C struct array?
Thanks a lot, bro. This methodology works fine in the code I was making.
– user237530