在C程序完成暂停屏幕 [英] Pause screen at program completion in C

查看:114
本文介绍了在C程序完成暂停屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够做到沿 $ P $的东西线PSS任意键退出在程序完成,但还没有能够弄清楚如何

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]);
    }
}

有什么建议?

我使用的 MonoDevelop的 五笔 如果让任何区别。

I am using MonoDevelop in Wubi, if that makes any difference.

推荐答案

要做到这一点快速破解,最常见的两个选项是:

To do this quick hack, the most common two options are:

/* Windows only */
#include <stdlib.h>

system("pause");

/* Cross platform */
#include <stdio.h>

printf("Press enter to continue...\n");
getchar();

我认为后一种方法,虽然第一种方法的任意键触发真的,而底面合一只触发输入。

I suggest the latter method, though the first method really triggers on "any" key while the bottom one only triggers on enter.

这篇关于在C程序完成暂停屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆