C语言凝视->C++凝视即/*xxxxx*/->//xxxxx


在转换凝视前我们先了解一个概念:什么是有限状态机?
有限状态机FSM是软件上经常使用的一种处理方法,它把复杂的控制逻辑分解成有限个稳定状态。在每一个状态上进行处理。

有限状态机是闭环系统。能够用有限的状态,处理无穷的事务。
// 通常我们使用多路分之语句来处理状态机。即switch()、case语句

//input.c中要处理的情况例如以下

input.c:

//1.普通情况

/*int i = 0;*/

//2.换行问题

/*int y = 0;*/int j = 0;

//3.匹配问题

/*int x = 0;/*12345678*/

//4.多行凝视问题

/*

int h = 0;

int g = 0;

int j = 0;

*/int q = 0;

//5.连续凝视问题

/**//**/

//6.连续的**/问题

/* ****** */

//7.C++凝视问题

// /*1234567890*/

//8.C凝视本身不匹配问题

/*int i = 0;

源文件Annotationconvert.c

<span style="font-size:18px;">#include<stdio.h>
#include<errno.h>
#include<assert.h>
#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 != '\n')
{
fputc(next, outfile);
next = fgetc(infile);
}
a = tag_end;
}
else
{
fputc(firstch, outfile);
fputc(secondch, outfile);
}
break;
case'*':
secondch = fgetc(infile);
if (secondch == '/')
{
fputc('\n', outfile);
a = tag_end;
}
else if (secondch == '*')
{
fputc(firstch, outfile);
fseek(infile, -1, SEEK_CUR);
}
else
{
fputc(firstch, outfile);
fputc(secondch, outfile);
}
break;
case'\n':
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\n", errno);
}
else if (ret == FILE_SUCCESS)
{
printf("转换成功\n");
}
else if (other_error)
{
printf("其它错误:%d\n", errno);
}
else
{
printf("不匹配\n");
} return 0;
}</span>

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. JSONObject转换JSON--将Date转换为指定格式

    项目中,经常会用JSONObject插件将JavaBean或List<JavaBean>转换为JSON格式的字符串,而JavaBean的属性有时候会有java.util.Date这个类型的 ...

  2. SQL 行列转换数据转换为字符串

    行列转换,将列数据转换为字符串输出 ) SET @center_JZHW = ( SELECT DISTINCT STUFF( ( SELECT ',' + ce_code FROM ap_cente ...

  3. C# DataTable转换成DataRow

    linq中的cast<T>()及OfType<T>() DataTable dt=...........//获取从数据库中取出的数据(假设只有一条记录) //Cast<T ...

  4. C++的显示转换

    利用显示转换使得我们可以很容易发现它们,因为通过名字就能找到:  static_cast 用于“良性”和“适度良性”转换,包括不用强制转换  const_cast  对“const”和“volatil ...

  5. QT类型转换(九种转换)

    1.char * 与 const char *的转换 char *ch1="hello11";const char *ch2="hello22";ch2 = c ...

  6. Qt中的对象类型转换(Qstring 转换char*有三种方法)

    char * 与 const char *的转换 char *ch1="hello11"; const char *ch2="hello22"; ch2 = c ...

  7. Qt中所有类型之间的转换

    1.char * 与 const char *的转换 char *ch1="hello11";const char *ch2="hello22";ch2 = c ...

  8. c++构造函数隐式转换--转换构造函数

    其实我们已经在C/C++中见到过多次标准类型数据间的转换方式了,这种形式用于在程序中将一种指定的数据转换成另一指定的类型,也即是强制转换,比如:int a = int(1.23),其作用是将1.23转 ...

  9. C++ Primer 学习笔记_63_重载运算符和转换 --转换和类类型【上】

    重载运算符和转换 --转换与类类型[上] 引言: 在前面我们提到过:能够用一个实參调用的位 unsignedchar 相同范围的值,即:0到255. 这个类能够捕获下溢和上溢错误,因此使用起来比内置u ...

随机推荐

  1. TCP三次握手及四次挥手详解及常见面试题

    https://blog.csdn.net/ZWE7616175/article/details/80432486

  2. django基础(web框架,http协议,django安装)

    学习Django之前我们先来看什么是OSI七层模型: 应用层 表示层       应用层(五层模型中把这三层合成一个应用层) http协议 会话层 传输层                  提供端口对 ...

  3. Charles-安装和配置

    一. 安装.破解charles工具 1. 安装压缩包中的charles_setup.exe,安装完成后先不启动charles. 2. 在安装文件中找到crack文件,将文件中的charles.jar拷 ...

  4. Android App性能自动化评测方法

    前言 App运行在设备上的性能表现也是质量保障的一个重要环节.因此,当我们确保了基本功能的准确之后,还需要有一定的方法评测App在不同设备上的性能表现.本文将从性能指标,评测方法,自动化体系建设等三个 ...

  5. 08-为数组和arguments

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  6. IntelliJ IDEA 代码提示快捷键

    1.写代码时用Alt-Insert(Code|Generate…)可以创建类里面任何字段的getter与setter方法. mac版 是ctrl+enter 2.CodeCompletion(代码完成 ...

  7. BZOJ 2298: [HAOI2011]problem a【动态规划】

    Description 一次考试共有n个人参加,第i个人说:“有ai个人分数比我高,bi个人分数比我低.”问最少有几个人没有说真话(可能有相同的分数) Input 第一行一个整数n,接下来n行每行两个 ...

  8. BZOJ 2190仪仗队【欧拉函数】

    问题的唯一难点就是如何表示队长能看到的人数?如果建系,队长所在的点为(0,0)分析几组数据就一目了然了,如果队长能看到的点为(m,n),那么gcd(m,n)=1即m n 互质或者是(0,1),(1,0 ...

  9. hdu 4819 Mosaic 树套树 模板

    The God of sheep decides to pixelate some pictures (i.e., change them into pictures with mosaic). He ...

  10. [暑假集训--数位dp]hdu2089 不要62

    杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍, ...