凝视转换(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 ...
随机推荐
- 82. Spring Boot – 启动彩蛋【从零开始学Spring Boot】
我们在[28. SpringBoot启动时的Banner设置 ] 这一小节介绍过设置Spring Boot的Banner,但是实际当中,我们希望做的更漂亮,所以也就有了这小节Spring Boot-启 ...
- 九度oj 题目1250:矩阵变换
题目描述: 对于一个整数矩阵,存在一种运算,对矩阵中任意元素加一时,需要其相邻(上下左右)某一个元素也加一, 现给出一正数矩阵,判断其是否能够由一个全零矩阵经过上述运算得到. 输入: 输出: 如果可以 ...
- oracle用户密码错误导致用户锁定
解决方法:使用DBA用户将其解锁: SQL> alter user ecology account unlock; 用户已更改. 用户密码限制设置: 查看FAILED_LOGIN_ATTEMPT ...
- POJ——3126Prime Path(双向BFS+素数筛打表)
Prime Path Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16272 Accepted: 9195 Descr ...
- BZOJ 2463: [中山市选2009]谁能赢呢?【博弈】
这题不科学~~本以为鬼谷子的钱袋是能在BZOJ写的最短的程序了,这题还要短…..好吧,思考难度神马的还是有点的(至少对我这种蒟蒻来说).很明显这是道博弈论的题目,在纸上画出了n=1~4的博弈树,发现b ...
- java面试题之能创建volatile数组吗?
答:能,只不过只是一个指向数组的引用,而不是整个数组,如果改变了引用指向的数组,将会受到volatile的保护,但是如果多个线程同时改变数组的元素,volatile关键字就不能起到保护的作用.
- uva 11995 判别数据类型
Problem I I Can Guess the Data Structure! There is a bag-like data structure, supporting two operati ...
- 拯救小矮人(codevs 2544)
题目描述 Description 一群小矮人掉进了一个很深的陷阱里,由于太矮爬不上来,于是他们决定搭一个人梯.即:一个小矮人站在另一小矮人的肩膀上,知道最顶端的小矮人伸直胳膊可以碰到陷阱口.对于每一个 ...
- .net面试题汇总-第二篇
本篇主要关注下,.net面试题中经常用的算法问题 1.有一群猴子,它们每天要吃桃子,它们第一天吃的数量是总量的一半再多一个,第二天吃的是第一天剩下的一半再多一个,第三天吃的是第二天剩下的一半多一个,以 ...
- SQLite数据库相关操作
一.创建数据库 这里创建了note便签数据表,字段有noteId.noteTitle.noteTime.noteInfo ); // TODO Auto-generated constructor ...