自己写的一个vii总结
2016-02-13 20:30
447 查看
#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界面。需要进一步完善。
#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界面。需要进一步完善。
相关文章推荐
- 字符串_笔记
- 关于coursera上Learning How to Learn课程的读书笔记
- 懒加载的一些理解
- Java中泛型中的几个符号
- LeetCode 2015.7.13 9,21,104,6,191,198,204,225
- bzoj 4016 [FJOI2014]最短路径树问题(最短路径树+树分治)
- iOS 获取项目文件路径
- 杭电1059Windows Message Queue
- LeetCode 2015.7.10 26,58,226
- 一致性Hash算法
- LeetCode 2015.7.9 66,67,70,83,88,100
- 算法精讲学习笔记 队列和栈
- github 和 jupyter
- FPGA中的时序分析(二)
- 在MFC类中各种类的指针的获取和应用
- “红包”
- bestcoder#71
- view文档的分栏
- LeetCode 2015.7.7 205,206,217,219,223,228,231,111,112
- LeetCode 2015.7.8 128,171,172,189,202,203,119