在上一篇博客里面我自己实现了一个命令解释器,那么这个我们先看看最常用的命令,在这片博客里面我们将会看到,两个简单命令的实现,pwd和 clear 。
第一个:pwd
#include<stdio.h>
#include<pwd.h>
#include<string.h>
#include<assert.h>
int main()
{
char path[128] = {0};
getcwd(path,128);
printf("%s\n",path);
return 0;
}
看着则么简单的代码,相信大家觉得很简单,getcwd();获得当前的路径。
第二个:clear
#include<stdio.h>
#include<unistd.h>
#include<dirent.h>
#include<string.h>
#include<stdlib.h>
#include<sys/stat.h>
int main()
{
printf("\033[H\033[2J"); // \033[y;xH设置光标位置 033[h 设置光标到0行0列,\033[2j 清屏
return 0;
}
printf这个的参数有很多,具体在这个里面有介绍:http://blog.csdn.net/qq_35256722/article/details/53323068