胡军铁木真电视剧全集:请问SYSTEM()包含在那个头文件中
来源:百度文库 编辑:查人人中国名人网 时间:2024/07/03 08:38:14
#include <stdlib.h>即可
原型:int system(const char *command)
作用:调用DOS命令
参数解释:command——DOS命令字符串
返回值见楼上
需要注意的是:该函数对字符串的处理和c中的习惯一致,比如说:如果输出反斜杠需要 \\
例如:
system("dir c:\\windows");
注意转义字符等的限制就可以了,其他的按照dos命令的习惯来就对了。
process.h
stdlib.h
把dos 命令当作入口函数
比如说
system("dir");
system("cd c:\tc");
system("a.bat");
成功了返回0 失败了返回-1
#include <stdio.h>
#define MAX_BUF 80
void change_file_name(char*);
static const char* file_name = "find_list.list";
static char exec_str[MAX_BUF * 2];
int main()
{
FILE* fp;
char buf[MAX_BUF];
char flag;
int index;
//create the search list
sprintf(exc_str, "find ./ -name *.h > %s", file_name);
system(exec_str);
if ((fp = fopen(file_name, "r")) == NULL) {
printf("can not open the find list file.\n");
return;
}
index = 0;
while (!feof(fp)) {
fscanf(fp, "%s\n", buf);
sprintf(exec_str, "sed -i 's/oldstring/newstring/' %s", buf);
system(exec_str);
}
fclose(fp);
//delete the search list
sprintf(exc_str, "rm -fr %s", file_name);
system(exec_str);
}
记得加分哈!:)