Are there no proper initialising of array for the infitite loop?

[b][red]This message was edited by tokoG at 2006-2-1 20:27:45[/red][/b][hr]I've been asking this question on my school msg board but all the replies I am getting sound like if there is no proper way of initialising an array for the infinite loop for example as follows;

This programme I wrote below WORKS.But it doesn't end the programme properly instead I get this 'Access Violation' pop-up msg.

If I want to make this programme infinite, how should I [red]properly[/red] initialise so that I can end the programme by ENTER and won't get the pop-up msg?

Comments

: [b][red]This message was edited by tokoG at 2006-2-1 20:27:45[/red][/b][hr]: I've been asking this question on my school msg board but all the replies I am getting sound like if there is no proper way of initialising an array for the infinite loop for example as follows;: : This programme I wrote below WORKS.: But it doesn't end the programme properly instead I get this 'Access Violation' pop-up msg.: : If I want to make this programme infinite, how should I [red]properly[/red] initialise so that I can end the programme by ENTER and won't get the pop-up msg?: : Thanks!!: : [code]: #include: : void main () {: : int numbers[]={0}, i=0, length;: : while (1) {: printf("Input an integer and use -1 to end: ");: scanf("%d", &numbers[i]);: fflush(stdin);: if (numbers[i] == -1): break;: else: i++;: : }: : length = i-1;: printf("

: [b][red]This message was edited by tokoG at 2006-2-1 20:27:45[/red][/b][hr]: I've been asking this question on my school msg board but all the replies I am getting sound like if there is no proper way of initialising an array for the infinite loop for example as follows;: : This programme I wrote below WORKS.: But it doesn't end the programme properly instead I get this 'Access Violation' pop-up msg.: : If I want to make this programme infinite, how should I [red]properly[/red] initialise so that I can end the programme by ENTER and won't get the pop-up msg?: : Thanks!!: : [code]: #include: : void main () {: : int numbers[]={0}, i=0, length;: : while (1) {: printf("Input an integer and use -1 to end: ");: scanf("%d", &numbers[i]);: fflush(stdin);: if (numbers[i] == -1): break;: else: i++;: : }: : length = i-1;: printf("

Numbers in reverse order");: for (i=length; i >= 0; i--): printf("%d ", numbers[i]);: : getchar();: }: [/code]: I think a good way to achieve such a task would be to use a dynamic list, instead of resizing an array.

: Hi: : Does this code you posted suppose to work on C++ Bulder?: I tried but I got the strange msg. I am beginner and not familier with this type of msg. If you'd like to read it, I will post it though.: : xx: : tokoG: Which code are you talking about? Stober's one or mine? Mine is written in C and was tested with Borland C Builder 5. Stober's code is in C++, and since I don't know C++, I cannot tell more :-). However, it comes from Stober so I think it should work.