如何从简单的C程序清屏? [英] How to clear screen from simple C program?

查看:334
本文介绍了如何从简单的C程序清屏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <stdio.h>
#include <cstdlib>

rec();

main() 
{
    int a, fact;
    char q, n, y;
    printf("\nEnter any number ");
    scanf("%d", & a);
    fact = rec(a);
    printf("Factorial value = %d\n", fact);
    printf("do you want to exit.....(y/n):");
    scanf("%s" ,&q);
    if (q == 'n')
    {
        system("cls");
        main();
    }
    else
        return 0;
}

rec(int x) 
{
    int f;
    if (x == 1) 
        return 1;
    else 
        f = x * rec(x - 1);

    return f;
}

我使用code块,但我不知道如何清除屏幕。我搜索,然后找到系统(CLS); 头文件中的#包括&LT; cstdlib&GT; ,但它显示了误差 cstdlib:目录中没有这样的文件。我应该怎么办?

I'm using code blocks but I don't know how to clear the screen. I searched then found system("cls"); within header file #include<cstdlib>, but it shows the error cstdlib: no such file of directory. What should I do ?

推荐答案

清除屏幕是正常的C程序的范围之外。这取决于操作系统。

Clearing the screen is outside the purview of a normal C program. It depends on the operating system.

有关窗口,你应该看看 conio

For windows, you should look into conio.

对于UNIX,看看诅咒问题或< A HREF =/问题/标记/ termios的类=标签后称号=显示标记的问题'的termios'的rel =标签>的termios 。

For unix, look into curses or termios.

系统()总是启动子壳可能会或可能不会对父程序的环境的任何影响。您的的需要的系统调用的,但是的的一个系统()电话。

system() always launches a sub-shell which may or may not have any effect on the environment of the parent program. You do need a system-call, but not a system() call.

我并不总是知道这一点。我曾经(不久前)在comp.lang.c建议,应该有人尝试系统(退出); 来紧密围绕DOS程序的窗口。但是,当然,不能工作。而我连忙劝发布前测试我的code。 :)

I didn't always know this. I once (long ago) suggested in comp.lang.c that someone should try system("exit"); to close the window around the DOS program. But that, of course, cannot work. And I was quickly advised to test my code before posting. :)

这篇关于如何从简单的C程序清屏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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