❶ c语言中 system的各种参数
注:这是CSDN上的RookieStar回答的
我以这个为测试为例:system( "abcde ");
显示如下:
'abcde ' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
Press any key to continue
这个很能说明问题:在windows操作系统下,system()函数真正调用的是命令解释器文件cmd.exe,这个我想你应该知道吧,通过解释器将传入的字符串转成相应的内部/外部命令或可运行程序以及批处理文件,就能解决你关于pause(内部指令)、clrscr(外部命令)的问题了。不过这里还有个小问题,我的中文XP下cmd似乎也是英文版本的,所以pause显示英文,而console程序显示的是中文,我个人理解是console程序与操作系统间有密切关系(可能存在语言的转译或内部调用一个中文的cmd),所以console程序结果与cmd结果在内容上有语言的区别。至于内部指令的实现问题,还是让m$好好教你吧! :)
顺便附上msdn中关于system函数的说明,供你参考:
system, _wsystem
Execute a command.
int system( const char *command );
int _wsystem( const wchar_t *command );
Routine Required Header Compatibility
system <process.h> or <stdlib.h> ANSI, Win 95, Win NT
_wsystem <process.h> or <stdlib.h> or <wchar.h> Win NT
For additional compatibility information, see Compatibility in the Introction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
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, and errno is set to one of the following values:
E2BIG
Argument list (which is system-dependent) is too big.
ENOENT
Command interpreter cannot be found.
ENOEXEC
Command-interpreter file has invalid format and is not executable.
ENOMEM
Not enough memory is available to execute command; or available memory has been corrupted; or invalid block exists, indicating that process making call was not allocated properly.
Parameter
command
Command to be executed
Remarks
The system function passes command to the command interpreter, which executes the string as an operating-system command. system refers to the COMSPEC and PATH environment variables that locate the command-interpreter file (the file named CMD.EXE in Windows NT). If command is NULL, the function simply checks to see whether the command interpreter exists.
You must explicitly flush (using fflush or _flushall) or close any stream before calling system.
_wsystem is a wide-character version of system; the command argument to _wsystem is a wide-character string. These functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tsystem system system _wsystem
Example
/* SYSTEM.C: This program uses
* system to TYPE its source file.
*/
#include <process.h>
void main( void )
{
system( "type system.c " );
}
Output
/* SYSTEM.C: This program uses
* system to TYPE its source file.
*/
#include <process.h>
void main( void )
{
system( "type system.c " );
}
❷ 在c语言中system有什么功能,如何使用
可以调用系统命令,如system("pause"),可以使程序暂停,保持窗口显示,否则程序就立刻退出了
❸ C语言中system函数的用法
函数名: system
功 能: 发出一个DOS命令
用 法: int system(char *command);
程序例:
#include
#include
int main(void)
{
printf("About to spawn command.com and run a DOS command\n");
system("dir"); //这里就是DOS下的dir命令
return 0;
}
❹ c语言中的system(“pause”)是什么意思
system("pause")语句执行系统环境中的pause命令,冻结屏幕,用户按任意键结束。
system函数是C语言标准库的一个函数,可以调用系统环境中的程序
如语句
system("echo hello");
等同于在命令提示符中执行echo
hello命令(当然不同的系统命令不同,这里不一一列举)
❺ C语言中system("pause")是什么作用和意思
system(“pause”) 是调用DOS系统的暂停命令 pause 来暂停程序执行,按任意一个键后将继续执行。
Sleep() 是 windows 的 函数,让程序进入睡眠状态,要求参数 时间毫秒,到时间后自动苏醒,程序继续执行。
例如: Sleep(2500); 休眠 2.5 秒,满2.5 秒 后 程序继续运行。
❻ C语言的system函数
system(系统)函数
windows操作系统下system () 函数详解(主要是在C语言中的应用)
功 能: 发出一个DOS命令
用 法: int system(char *command);
system函数已经被收录在标准c库中,可以直接调用
程序例:
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
printf("About to spawn and run a DOS command\n");
system("dir");
return 0;
}
又如:system("pause")可以实现冻结屏幕,便于观察程序的执行结果;system("CLS")可以实现清屏操作。而调用color函数可以改变控制台的前景色和背景,具体参数在下面说明。
例如,用 system("color 0A"); 其中color后面的0是背景色代号,A是前景色代号。各颜色代码如下:
0=黑色 1=蓝色 2=绿色 3=湖蓝色 4=红色 5=紫色 6=黄色 7=白色 8=灰色 9=淡蓝色 A=淡绿色 B=淡浅绿色 C=淡红色 D=淡紫色 E=淡黄色 F=亮白色
(注意:Microsoft Visual C++6.0 支持system)
举例
看了下面实例,相信你会对学到更多system在C程序设计中的应用。
例一:
C语言调用DOS命令实现定时关机:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int print()
{
printf(" ╪╪╪╪╪╪╧╧╧╧╧╧╧╧╪╪╪╪╪╪\n");
printf("╔═══╧╧C语言关机程序 ╧╧═══╗\n");
printf("║※1.实现10分钟内的定时关闭计算机 ║\n");
printf("║※2.立即关闭计算机 ║\n");
printf("║※3.注销计算机 ║\n");
printf("║※0.退出系统 ║\n");
printf("╚═══════════════════╝\n");
return 0;
}
void main()
{
system("title C语言关机程序");//设置cmd窗口标题
system("mode con cols=48 lines=25");//窗口宽度高度
system("color 0B");
system("date /T");
system("TIME /T");
char cmd[20]="shutdown -s -t ";
char t[5]="0";
print();
int c;
scanf("%d",&c);
getchar();
switch(c)
{
case 1:printf("您想在多少秒后自动关闭计算机?(0~600)\n");scanf("%s",t);system(strcat(cmd,t));break;
case 2:system("shutdown -p");break;
case 3:system("shutdown -l");break;
case 0:break;
default:printf("Error!\n");
}
system("pause");
exit(0);
}
例二:
用C语言删除文件,例如文件的位置是d:\123.txt
用system()函数执行windows命令。
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
system("del d:\\123.txt");
return 0;
}
❼ c语言中system是什么
相当于Basic里的shell(),这个叫外壳
比如:
system("ping sina.com.cn");
/* ping新浪 */
system("dir c:\ /a/w");
/* 查看C盘根目录下所有文件
❽ C语言system函数用法
system函数 是可以调用一些DOS命令,比如
system("cls");//清屏,等于在DOS上使用cls命令
写可执行文件路径,可以运行它····
下面列出常用的DOS命令,都可以用system函数调用:
ASSOC 显示或修改文件扩展名关联。
AT 计划在计算机上运行的命令和程序。
ATTRIB 显示或更改文件属性。
BREAK 设置或清除扩展式 CTRL+C 检查。
CACLS 显示或修改文件的访问控制列表(ACLs)。
CALL 从另一个批处理程序调用这一个。
CD 显示当前目录的名称或将其更改。
CHCP 显示或设置活动代码页数。
CHDIR 显示当前目录的名称或将其更改。
CHKDSK 检查磁盘并显示状态报告。
CHKNTFS 显示或修改启动时间磁盘检查。
CLS 清除屏幕。
CMD 打开另一个 Windows 命令解释程序窗口。
COLOR 设置默认控制台前景和背景颜色。
COMP 比较两个或两套文件的内容。
COMPACT 显示或更改 NTFS 分区上文件的压缩。
CONVERT 将 FAT 卷转换成 NTFS。您不能转换
当前驱动器。
COPY 将至少一个文件复制到另一个位置。
DATE 显示或设置日期。
DEL 删除至少一个文件。
DIR 显示一个目录中的文件和子目录。
DISKCOMP 比较两个软盘的内容。
DISKCOPY 将一个软盘的内容复制到另一个软盘。
DOSKEY 编辑命令行、调用 Windows 命令并创建宏。
ECHO 显示消息,或将命令回显打开或关上。
ENDLOCAL 结束批文件中环境更改的本地化。
ERASE 删除至少一个文件。
EXIT 退出 CMD.EXE 程序(命令解释程序)。
FC 比较两个或两套文件,并显示
不同处。
FIND 在文件中搜索文字字符串。
FINDSTR 在文件中搜索字符串。
FOR 为一套文件中的每个文件运行一个指定的命令
FORMAT 格式化磁盘,以便跟 Windows 使用。
FTYPE 显示或修改用于文件扩展名关联的文件类型。
GOTO 将 Windows 命令解释程序指向批处理程序
中某个标明的行。
GRAFTABL 启用 Windows 来以图像模式显示
扩展字符集。
HELP 提供 Windows 命令的帮助信息。
IF 执行批处理程序中的条件性处理。
LABEL 创建、更改或删除磁盘的卷标。
MD 创建目录。
MKDIR 创建目录。
MODE 配置系统设备。
MORE 一次显示一个结果屏幕。
MOVE 将文件从一个目录移到另一个目录。
PATH 显示或设置可执行文件的搜索路径。
PAUSE 暂停批文件的处理并显示消息。
POPD 还原 PUSHD 保存的当前目录的上一个值。
PRINT 打印文本文件。
PROMPT 更改 Windows 命令提示符。
PUSHD 保存当前目录,然后对其进行更改。
RD 删除目录。
RECOVER 从有问题的磁盘恢复可读信息。
REM 记录批文件或 CONFIG.SYS 中的注释。
REN 重命名文件。
RENAME 重命名文件。
REPLACE 替换文件。
RMDIR 删除目录。
SET 显示、设置或删除 Windows 环境变量。
SETLOCAL 开始批文件中环境更改的本地化。
SHIFT 更换批文件中可替换参数的位置。
SORT 对输入进行分类。
START 启动另一个窗口来运行指定的程序或命令。
SUBST 将路径跟一个驱动器号关联。
TIME 显示或设置系统时间。
TITLE 设置 CMD.EXE 会话的窗口标题。
TREE 以图形模式显示驱动器或路径的目录结构。
TYPE 显示文本文件的内容。
VER 显示 Windows 版本。
VERIFY 告诉 Windows 是否验证文件是否已正确
写入磁盘。
VOL 显示磁盘卷标和序列号。
XCOPY 复制文件和目录树。
❾ C语言中system是什么意思
system是一个函数,用于运行其它外部程序。
函数原型:intsystem(constchar*string);
示例:以下程序在vc6.0中编译通过,通过system函数,打开记事本程序。
#include<stdlib.h>
intmain()
{
system("notepad.exe");
return0;
}
问题中的system("cls"),是执行一个CMD中的命令cls,这是清屏命令。
❿ 在C语言中,程序有一个是system("CLS");时什么意思
在C语言程序中是清屏的意思。
当你编写的程序有输出的时候,如果要进行多次调试,屏幕上会显示很多次的输出的结果,看上去非常的复杂非常的乱。那么我们就可以在程序中的输出语句之前加上“system("CLS");”,当我们用上这条语句之后。
这样每次程序运行的时候都会将上一次运行输出的内容给清除掉,屏幕上只显示本次输出的结果。这样看起来就非常的简洁。
(10)system中的c语言扩展阅读:
在VC环境下有两种办法实现清屏:
1、#include <windows.h>
system("cls");这种办法的缺点是程序额外运行系统程序执行清屏操作,延长了程序执行时间。
2、自己写函数,这种办法快
这是从微软MSDN得到的方法:
/* Standard error macro for reporting API errors */
#define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s
on line %d ", __FILE__, GetLastError(), api, __LINE__);}
void cls( HANDLE hConsole )
{
COORD coordScreen = { 0, 0 }; /* here's where we'll home the
cursor */
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
DWORD dwConSize; /* number of character cells in
the current buffer */
/* get the number of character cells in the current buffer */
bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "GetConsoleScreenBufferInfo" );
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
/* fill the entire screen with blanks */
bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ',
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputCharacter" );
/* get the current text attribute */
bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "ConsoleScreenBufferInfo" );
/* now set the buffer's attributes accordingly */
bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputAttribute" );
/* put the cursor at (0, 0) */
bSuccess =SetConsoleCursorPosition( hConsole, coordScreen );
PERR( bSuccess, "SetConsoleCursorPosition" );
return;
}
参考资料来源:网络-system("cls")