I want to be able to do something along the lines of Press any key to exit
at program completion, but have no been able to figure out how to.
When I run my program, the terminal exits before I can see the results.
//by Nyxm
#include <stdio.h>
main() {
int temp, x, flag, num, size;
printf("\nEnter how many numbers you wish to enter: ");
scanf("%d", &size);
int array[size];
for (x = 0; x < size; x++) {
printf("Enter an integer: ");
scanf("%d", &num);
array[x] = num;
}
printf("Please enter either 1 or 2\n1:\tAscending\n2:\tDescending\n\n...");
scanf("%d", &num);
if (num == 1) {
flag = 0;
while (flag == 0) {
flag = 1;
for (x = 1; x < size; x++) {
if (array[x] < array[x-1]) {
flag = 0;
temp = array[x];
array[x] = array[x-1];
array[x-1] = temp;
}
}
}
} else {
flag = 0;
while (flag == 0) {
flag = 1;
for (x = 1; x < size; x++) {
if (array[x] < array[x-1]) {
flag = 0;
temp = array[x];
array[x] = array[x-1];
array[x-1] = temp;
}
}
}
}
printf("\nYour sorted array:\n");
for (x = 0; x < size; x++) {
printf("%d\n", array[x]);
}
}
Any suggestions?
I am using MonoDevelop
in Wubi
, if that makes any difference.
To do this quick hack, the most common two options are:
and
I suggest the latter method, though the first method really triggers on "any" key while the bottom one only triggers on enter.