How to clear screen from simple C program?

牧云@^-^@ 提交于 2019-12-04 19:56:20

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

For windows, you should look into .

For unix, look into or .

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.


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. :)

Change

#include <cstdlib>

to

#include <stdlib.h>

cstdlib is a C++ header file, and thus will be unusable in C.

you have lots of problems in your code....

but for the specific problem, try #include <stdlib.h>

use the #include<stdlib.h> that's where the clear screen function is defined.

Mike

To use system("cls") you need the header <iostream>. This will allow all system() types to execute. Unsure if it is a C++ header file, but it works for the compiler that I use.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!