system函数--执行输入的系统命令

目录

system的作用

system库函数

system所需要的头文件

system的返回值

system在代码中的应用--清空屏幕


system的作用

执行命令

system库函数

通过这张图我们可以很好的了解到这个库函数的使用方式 

system所需要的头文件

 因为system函数是一个和系统有关的函数,所以头文件是<process.h>或<stdlib.h>

system的返回值

If command is NULL and the command interpreter is found, the function returns a nonzero value.
If the command interpreter is not found, it returns 0 and sets errno to ENOENT.
If command is not NULL, system returns the value that is returned by the command interpreter.
It returns the value 0 only if the command interpreter returns the value 0. A return value of – 1 indicates an error

如果命令为NULL并且找到了命令编辑器,则返回非零值
如果没有找到命令编辑器,则返回0并且将errno变成ENOENT
如果命令解释器不为NULL,系统将会返回命令编辑器返回的值
仅当命令解释器返回值0时,它才会返回值0。返回值–1表示错误

system在代码中的应用--清空屏幕

#include<stdio.h>
#include<string.h>
#include<windows.h>
#include<process.h>
int main()
{
	char arr1[] = "hello world!!!!";
	char arr2[] = "               ";
	int left = 0;
	int right = strlen(arr1) - 1;
	while (left <= right)
	{
		arr2[left] = arr1[left];
		left++;
		printf("%s\n", arr2);
		Sleep(1000);//单位毫秒
		system("cls");//清空屏幕
	}
	printf("%s", arr2);
	return 0;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一起慢慢变强

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值