注释转换(c转换为c++)
程序员文章站
2023-11-02 18:07:16
//input.c中要处理的情况如下
input.c
/*int i = 0;*/
/*int y = 0;*/int j = 0;
/*int x = 0;/*12345678*/
/*
in...
//input.c中要处理的情况如下
input.c
/*int i = 0;*/
/*int y = 0;*/int j = 0;
/*int x = 0;/*12345678*/
/*
int h = 0;
int g = 0;
int j = 0;
*/int q = 0;
/**//**/
/* ****** */
// /*1234567890*/
源文件annotationconvert.c
#include #include #include #pragma warning(disable:4996) typedef enum state { file_error, //文件错误 file_success, //文件成功 other_error, //其他错误 no_match, //文件不匹配 }sta; typedef enum tag { tag_begin, //注释中 tag_end, //不在注释中 }tag; sta annotationconvert(file* infile, file* outfile) { char firstch, secondch; int next; assert(infile); assert(outfile); tag a = tag_end; do{ firstch = fgetc(infile); switch (firstch) { case'/': secondch = fgetc(infile); if (secondch == '*' && a == tag_end) { fputc('/', outfile); fputc('/', outfile); a = tag_begin; } else if (secondch == '/') { fputc(firstch, outfile); fputc(secondch, outfile); next = fgetc(infile); while (next != eof && next != ' ') { fputc(next, outfile); next = fgetc(infile); } a = tag_end; } else { fputc(firstch, outfile); fputc(secondch, outfile); } break; case'*': secondch = fgetc(infile); if (secondch == '/') { fputc(' ', outfile); a = tag_end; } else if (secondch == '*') { fputc(firstch, outfile); fseek(infile, -1, seek_cur); } else { fputc(firstch, outfile); fputc(secondch, outfile); } break; case' ': if (a == tag_begin) { fputc(firstch, outfile); fputc('/', outfile); fputc('/', outfile); } else { fputc(firstch, outfile); } break; default: fputc(firstch, outfile); break; } } while (firstch != eof); if (a == tag_end) { return file_success; } else { return no_match; } return 0; } sta startconvert() { sta s; const char* infilename = input.c; const char* outfilename = output.c; file* infile = fopen(infilename, r); file* outfile = fopen(outfilename, w); if (infile == null) { return file_error; } if (outfile == null) { fclose(infile); return file_error; } s = annotationconvert(infile, outfile); fclose(infile); fclose(outfile); return s; } int main() { sta ret = startconvert(); if (ret == file_error) { printf(文件错误:%d , errno); } else if (ret == file_success) { printf(转换成功 ); } else if (other_error) { printf(其他错误:%d , errno); } else { printf(不匹配 ); } return 0; }output.c中结果应如下:
//int i = 0;
//int y = 0;
int j = 0;
//int x = 0;/*12345678
//
//int h = 0;
//int g = 0;
//int j = 0;
//
int q = 0;
//
//
// ******
// /*1234567890*/
下一篇: 潺菜的功效和食用禁忌是什么?
推荐阅读
-
c/c++编程排坑(1)-- 数据类型的“安静”转换
-
c#中利用委托反射将DataTable转换为实体集的代码
-
注释转换(c转换为c++)
-
C++雾中风景11:厘清C++类型转换(static_cast,dynamic_cast,reinterpret_cast,const_cast)
-
用C#把文件转换为XML的代码
-
C++中的字符串输入输出,转自:https://www.cnblogs.com/zzw1024/p/10502011.html
-
C语言小项目—注释转换
-
C++负数类型转换,-1对256取模
-
【转载】C#中ToArray方法将List集合转换为对应的数组
-
VS2015中不同开发环境设置转换(C#->C++等)