
编写一个c语言程序,微型命令解释程序。
须具有下列5条命令cdir(列出当前文件和目录)ccopy文件1文件2(拷贝文件)cerase文件名(删除文件)Cdis(字符串)Cend(退出微型命令解释程序)...
须具有下列5条命令
cdir(列出当前文件和目录)
ccopy文件1 文件2(拷贝文件)
cerase 文件名(删除文件)
Cdis (字符串)
Cend (退出微型命令解释程序) 展开
cdir(列出当前文件和目录)
ccopy文件1 文件2(拷贝文件)
cerase 文件名(删除文件)
Cdis (字符串)
Cend (退出微型命令解释程序) 展开
1个回答
展开全部
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char ins[256];
char cmd[256];
while(1)
{
printf("input order: ");
fflush(stdin);
scanf("%[^\n]", ins);
if(strncmp(ins, "cdir", 4) == 0)
{
system("dir");
}
else if(strncmp(ins, "ccopy", 5) == 0)
{
sprintf(cmd, "copy %s", (char*)ins + 5);
system(cmd);
}
else if(strncmp(ins, "cerase", 6) == 0)
{
sprintf(cmd, "del -f %s", (char*)ins + 6);
system(cmd);
}
else if(strncmp(ins, "cdis", 4) == 0)
{
printf("%s\n", ins + 4);
}
else if(strncmp(ins, "cend", 4) == 0)
{
exit(0);
}
else
{
printf("unknown order!\n");
}
}
return 0;
}
给出一个简单的实现。望采纳。
#include <string.h>
#include <stdlib.h>
int main()
{
char ins[256];
char cmd[256];
while(1)
{
printf("input order: ");
fflush(stdin);
scanf("%[^\n]", ins);
if(strncmp(ins, "cdir", 4) == 0)
{
system("dir");
}
else if(strncmp(ins, "ccopy", 5) == 0)
{
sprintf(cmd, "copy %s", (char*)ins + 5);
system(cmd);
}
else if(strncmp(ins, "cerase", 6) == 0)
{
sprintf(cmd, "del -f %s", (char*)ins + 6);
system(cmd);
}
else if(strncmp(ins, "cdis", 4) == 0)
{
printf("%s\n", ins + 4);
}
else if(strncmp(ins, "cend", 4) == 0)
{
exit(0);
}
else
{
printf("unknown order!\n");
}
}
return 0;
}
给出一个简单的实现。望采纳。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询