C的小项目:注释转换
来源:互联网 发布:java生成二维数组 编辑:程序博客网 时间:2024/06/06 03:25
emmm。。。。。
第一次发博客,欢迎大家批评指点哈。
- 头文件:convert_comment.h
#ifndef __convert_comment__H__#define __convert_comment_H__#define INPUTFILE "input.c"#define OUTPUTFILE "output.c"enum { CSTATUS, //C注释状态 NULLSTATUS, //普通状态 CPPSTATUS, //C++注释状态 EOFSTATUS //结束状态};void convert_main();#endif
- 源文件,放函数
convert_comment.c
#include <stdio.h>#include <stdlib.h>#include "convert_comment.h"int status = NULLSTATUS;void do_null_status(FILE *ifp, FILE *ofp){ int ch = fgetc(ifp); switch (ch) { case '/': { int c = fgetc(ifp); switch (c) { case '/': fputc(ch, ofp); fputc(c, ofp); status = CPPSTATUS; break; case '*': { fputc(ch, ofp); fputc('/', ofp); status = CSTATUS; break; } break; case EOF:status = EOFSTATUS; break; default: status = NULLSTATUS; break; } } break; case '*': { int c = fgetc(ifp); switch (c) { case '/': fputc('\n', ofp); break; default: fputc(ch, ofp); ungetc(c, ofp); status = NULLSTATUS; break; } } break; case EOF:status = EOFSTATUS; break; default: fputc(ch, ofp); status = NULLSTATUS; break; }}void do_cpp_status(FILE *ifp, FILE *ofp){ int ch = fgetc(ifp); switch (ch) { case '\n':status = NULLSTATUS; break; case EOF:status = EOFSTATUS; break; default: fputc(ch, ofp); status = NULLSTATUS; break; }}void do_c_status(FILE *ifp, FILE *ofp){ int ch = fgetc(ifp); switch (ch) { case '*': { int c = fgetc(ifp); switch (c) { case '/': fputc('\n', ofp); status = NULLSTATUS; break; default: fputc(ch, ofp); fputc(c, ofp); status = CSTATUS; break; } } break; case EOF: status = EOFSTATUS; break; case '\n': fputc('\n', ofp); fputc('/', ofp); fputc('/', ofp); break; default: fputc(ch, ofp); status = CSTATUS; break; }}static void convert_work(FILE* ifp, FILE *ofp){ while (status != EOFSTATUS) { switch (status) { case NULLSTATUS:do_null_status(ifp, ofp); break; case CPPSTATUS:do_cpp_status(ifp, ofp); break; case CSTATUS:do_c_status(ifp, ofp); break; default: break; } }}void convert_main(){ FILE * ifp = fopen(INPUTFILE, "r"); FILE * ofp = fopen(OUTPUTFILE,"w"); if (ifp == NULL || ofp == NULL) { printf("..............."); return; } convert_work(ifp, ofp); fclose(ifp); fclose(ofp);}
3.源文件,放主函数
test.c
#include <stdio.h>#include <Windows.h>#include "convert_comment.h"int main(){ convert_main(); system("pause"); return 0;}
3.进行测试
阅读全文
0 0
- C的小项目:注释转换
- 注释转换(c->c++)小项目
- C语言小项目—注释转换
- c语言小项目----注释转换
- C语言小项目---注释转换
- C语言小项目-注释转换
- c语言小项目---注释转换
- C/C++小项目之注释转换
- C语言小项目--注释转换
- 小项目之C注释转换为C++注释状态
- C注释转换为C++注释小项目
- 小项目 | 注释转换
- C语言小项目—注释转换( C注释转换为C++注释 )
- 小项目之注释的转换
- 【小项目】注释风格转换(从C语言注释风格转换到C++注释风格)
- C语言小项目制作之---注释转换
- 注释转换小项目(c注释->到c++注释)
- 简单小项目:注释转换
- 多线程 Callable Runnable 与Future
- 基于 SquashFS 构建 Linux 可读写文件系统
- 浅析 Linux 初始化 init 系统 systemd
- bzoj3172: [Tjoi2013]单词
- bzoj1026: [SCOI2009]windy数
- C的小项目:注释转换
- 为什么spinlock需要提升IRQL到Dispatch Level?
- 三十分钟理解:双调排序Bitonic Sort,适合并行计算的排序算法
- gcc链接参数
- 通过程序设计几何图形(Shape)、矩形(Rectangle)、圆形(Circle)、正方形(Square)几种类型, 能够利用接口和多态性计算几何图形的面积和周长并显示。
- 2、按以下要求编写程序 (1) 编写Animal接口,接口中声明run() 方法 (2) 定义Bird类和Fish类实现Animal接口 (3) 编写Bird类和Fish类的测试程序,并调用其
- 1、利用String类或StringBuffer类的方法,对输入的Email地址进行有效性验证。提示:1)Email地址中应包含“@”和“.”符号;2)“@”
- (简单思维)HihoCoder
- GitHub 整理|那些优秀的开源时间日期选择器,总有一款适合你