目录
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;
}