【C语言】C语言注释转换成C++注释。
来源:互联网 发布:淘宝家居用品架子 编辑:程序博客网 时间:2024/05/16 06:25
1.一般情况
/* int i = 0; */2.换行问题
/* int i = 0; */int j = 0;
/* int i = 0; */
int j = 0;3.匹配问题
/int i = 0;/*xxxxx/4.多行注释问题
/*
int i=0;
int j = 0;
int k = 0;
*/int k = 0;5.连续注释问题
////6.连续的/问题**
//*7.C++注释问题
// /xxxxxxxxxxxx/
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <assert.h>typedef enum TAG{ TAGBEGIN, TAGEND,}TAG;typedef enum STATE{ SUCCESS, NO_MATCH,}STATE;STATE Annotation_Convert(FILE *infile, FILE *outfile){ TAG tag = TAGEND; assert(infile); assert(outfile); char firstCh, secondCh; do { firstCh = fgetc(infile); switch (firstCh) { case '/': secondCh = fgetc(infile); if (secondCh == '*' && tag == TAGEND)//处理一般情况以及匹配情况 { fputc('/', outfile); fputc('/', outfile); tag = TAGBEGIN; } else { fputc(firstCh, outfile); fputc(secondCh, outfile); if (secondCh == '/')//处理C++注释情况:// /*abcdefgh*/ { char next; do { next = fgetc(infile); fputc(next,outfile); } while (next != '\n' && next != EOF); } } break; case '*': secondCh = fgetc(infile); if (secondCh == '/') { char next = fgetc(infile); if (next != '\n' && next != EOF)//处理换行问题/*int i = 0;*/ in t j = 0; { //以及连续注释/**//**/情况 fputc('\n', outfile); fseek(infile, -1, SEEK_CUR); } tag = TAGEND; } else//处理连续**/情况:/********/ { fputc(firstCh, outfile); fseek(infile, -1, SEEK_CUR); } break; case '\n': fputc('\n', outfile); if (tag == TAGBEGIN)//处理多行注释情况/*int i = 0; { // int j = 0; fputc('/', outfile); // */int m = 0; fputc('/', outfile); } break; default: fputc(firstCh, outfile); break; } } while (firstCh != EOF); if (tag == TAGEND) { return SUCCESS; } else { return NO_MATCH; }}int main(){ STATE s; FILE *infile = fopen("input3.c", "r"); FILE *outfile = fopen("output3.c", "w"); if (infile == NULL) { perror("error"); exit(EXIT_FAILURE); } if (outfile == NULL) { fclose(infile); perror("error"); exit(EXIT_FAILURE); } s = Annotation_Convert(infile, outfile); if (s == SUCCESS) { printf("匹配成功!\n"); } if (s == NO_MATCH) { printf("不匹配!\n"); } fclose(infile); fclose(outfile); return 0;}
input.c
output.c
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++)
- 【C语言】C代码注释转换
- 注释转换(c语言->c++)
- 将c语言注释转换成c++注释
- 子序列的和(subsequence)
- 菜鸟网络业务支撑平台
- 2015061404 - sourceforge
- DICOM:dcm4chee奇葩逻辑浅析之UID修改
- iOS开发笔记--CocoaPods详解_进阶篇
- 【C语言】C语言注释转换成C++注释。
- 初探 iOS8 中的 Size Class
- 完成一个一对多关系的数据输入窗口,单选删除还有问题,待改进
- 对Extjs中store的多种操作
- Python入门教程--元组
- 推酷上一些比较好的文章
- UIView 渲染和内容管理
- Hadoop之——Hive笔记
- iOS开发笔记——CocoaPods详解_制作篇