凝视转换(c转换为c++)
C语言凝视->C++凝视即/*xxxxx*/->//xxxxx
//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++)的更多相关文章
- JSONObject转换JSON--将Date转换为指定格式
项目中,经常会用JSONObject插件将JavaBean或List<JavaBean>转换为JSON格式的字符串,而JavaBean的属性有时候会有java.util.Date这个类型的 ...
- SQL 行列转换数据转换为字符串
行列转换,将列数据转换为字符串输出 ) SET @center_JZHW = ( SELECT DISTINCT STUFF( ( SELECT ',' + ce_code FROM ap_cente ...
- C# DataTable转换成DataRow
linq中的cast<T>()及OfType<T>() DataTable dt=...........//获取从数据库中取出的数据(假设只有一条记录) //Cast<T ...
- C++的显示转换
利用显示转换使得我们可以很容易发现它们,因为通过名字就能找到: static_cast 用于“良性”和“适度良性”转换,包括不用强制转换 const_cast 对“const”和“volatil ...
- QT类型转换(九种转换)
1.char * 与 const char *的转换 char *ch1="hello11";const char *ch2="hello22";ch2 = c ...
- Qt中的对象类型转换(Qstring 转换char*有三种方法)
char * 与 const char *的转换 char *ch1="hello11"; const char *ch2="hello22"; ch2 = c ...
- Qt中所有类型之间的转换
1.char * 与 const char *的转换 char *ch1="hello11";const char *ch2="hello22";ch2 = c ...
- c++构造函数隐式转换--转换构造函数
其实我们已经在C/C++中见到过多次标准类型数据间的转换方式了,这种形式用于在程序中将一种指定的数据转换成另一指定的类型,也即是强制转换,比如:int a = int(1.23),其作用是将1.23转 ...
- C++ Primer 学习笔记_63_重载运算符和转换 --转换和类类型【上】
重载运算符和转换 --转换与类类型[上] 引言: 在前面我们提到过:能够用一个实參调用的位 unsignedchar 相同范围的值,即:0到255. 这个类能够捕获下溢和上溢错误,因此使用起来比内置u ...
随机推荐
- 【06】GitHub WiKi
[09]GitHub WiKi GitHub WiKi 能够帮助我们处理非结构化的页面集合,就像维基百科那样.我自己 NodeJS docs 就被我弄成 wiki 的样子. 几个页面,然后自定义侧边栏 ...
- Python常用操作符
Python常用操作符 1.成员关系操作符in 显示的数字前面填充'0'代替空格 6.转义字符 符号 含义 \' 单引号\" 双引号\a 发出系统响铃声\b 退格符\n 换行符\t 横向制表 ...
- mysql无法创建外键问题
在阿里云上面安装配置了Mysql后,无法创建外键, 原因及解决方法: 选择InnoDB引擎,因为MyISAM引擎不支持外键,默默地说一句,MySQL真神奇
- tensorflow在各种环境下搭建与对比
tensorflow在各种环境下搭建与对比 由于有些训练是要长时间进行训练(几天),才能看出显著的结果,如果只是通过本地的计算机进行训练是不可能的.因此这周花了一些时间调研如何才能让神经网络长时间的进 ...
- Convolution Fundamental II
Practical Advice Using Open-Source Implementation We have learned a lot of NNs and ConvNets architec ...
- Leetcode 396.旋转函数
旋转函数 给定一个长度为 n 的整数数组 A . 假设 Bk 是数组 A 顺时针旋转 k 个位置后的数组,我们定义 A 的"旋转函数" F 为: F(k) = 0 * Bk[0] ...
- POJ3630/HDU-1671 Phone List,字典树静态建树!
Phone List POJ动态建树TLE了~~~ 题意:拨打某个电话时可能会因为和其他电话号码的前几位重复而导致错误,现在给出一张电话单,求是否有某个电话是其他电话的前缀.是则输出NO,否则输出YE ...
- spring,mybatis事务管理配置与@Transactional注解使用
spring,mybatis事务管理配置与@Transactional注解使用[转] spring,mybatis事务管理配置与@Transactional注解使用 概述事务管理对于企业应用来说是 ...
- BZOJ 3209: 花神的数论题【数位dp】
Description 背景众所周知,花神多年来凭借无边的神力狂虐各大 OJ.OI.CF.TC …… 当然也包括 CH 啦.描述话说花神这天又来讲课了.课后照例有超级难的神题啦…… 我等蒟蒻又遭殃了. ...
- 关于java读取文件IO流学习总结(一)
IO流的分类: 1.根据流的数据对象来分: 高端流:所有的内存中的流都是高端流,比如:InputStreamReader 低端流:所有的外界设备中的流都是低端流,比如InputStream,Outpu ...