自己写的一个vii总结

时间:2023-03-09 19:34:48
自己写的一个vii总结

#include<stdlib.h>
#include<stdio.h>
#include<unistd.h>
#include<errno.h>
#include<error.h>
#include<string.h>
int main(int argc ,char **argv)
{
if(argc != 2)
{
printf("Usage:%s <xxx.c>\n",argv[0]);
exit(0);
}

FILE *fp = fopen(argv[1],"a+");
if(fp == NULL)
{
fprintf(stderr,"fopen (%s) is failed:%s\n",argv[1],strerror(errno));
exit(0);
}

fputs("#include<stdlib.h>\n",fp); //将一个字符串输出到file *stream中。

fputs("#include<stdio.h>\n",fp);
fputs("#include<string.h>\n",fp);
fputs("#include<error.h>\n",fp);
fputs("#include<errno.h>\n",fp);
fputs("#include<unistd.h>\n",fp);
fputs("#include<strings.h>\n",fp);
fputs("#include<stdbool.h>\n\n",fp);

fputs("#include<sys/stat.h>\n",fp);
fputs("#include<sys/types.h>\n",fp);
fputs("#include<sys/wait.h>\n",fp);
fputs("#include<fcntl.h>\n",fp);
fputs("int main(int argc,char **argv)",fp);
int fe = fflush(fp);
if(fe == EOF)  //error of file
{
fprintf(stderr,"flush (%s),failed:%s\n",argv[1],strerror(errno));//如果出错,输出错误信息
}
fclose(fp);
// fopen(argv[1],"a+");

return 0;

}

//本程序基本实现了vii的功能,还有一点缺陷就是,运行这个程序之后,所创建的文件不能直接以打开的形式呈现,需要另外vim file.c 才能进入vi界面。需要进一步完善。