我的項目是讓用戶輸入5000個數字到數組中,但允許他們隨時停止。我大部分的代碼都被關閉了,但是當用戶輸入「-1」然後顯示數組時,我無法知道如何停止所有的事情。這是我到目前爲止的代碼:當用戶輸入「-1」時獲取數組停止
#include <stdio.h>
#include<stdlib.h>
#define pause system("pause")
#define cls system("cls")
#define SIZE 50
int i;
main()
{
int i;
int userInput[SIZE];
for (i = 0; i < SIZE; i++)
{
printf("Enter a value for the array (-1 to quit): ");
scanf("%i", &userInput[i]);
} // end for
for (i = 0; i < SIZE; i++)
{
if (userInput[i] == -1)
printf("%i. %i\n", i + 1, userInput[i]);
pause;
} // end for
pause;
} // end of main
您不能「停止」數組。 – paddy