凝视转换(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 ...
随机推荐
- hdu_2070_Fibbonacci Number
这个题我用long long ,printf("%lld");输出就错误了 我用__int64,printf("%I64d");输出就正确了 这点需要注意. # ...
- heartbeat负载均衡详解
heartbeat高可用软件http://www.linux-ha.org/wiki/Main_Page 1 heartbeat作用通过heartbeat将资源(IP)从一台已经故障的计算机快速转移到 ...
- 安卓手机 HTML5 手机页面 输入表单被键盘遮挡住了
TML5 手机页面 输入表单被键盘遮挡住了 请问 大神 怎么 js 或者 JQ 判断安卓手机软键盘的键盘隐藏键按下去了? 有使用 uexWindow 方法 能判断到确定键 是 13 但是不知道这个键的 ...
- HackerRank# Hexagonal Grid
原题地址 铺瓷砖的变种,做法也是类似 假设地板长下面这样,灰色的是无法填充的空洞,初始时可以把N块之外的地板填充成灰色的,便于边界处理 假设现在从后向前已经处理完了一部分,绿色的砖块代表已经遍历过了, ...
- [UOJ#122][NOI2013]树的计数
[UOJ#122][NOI2013]树的计数 试题描述 我们知道一棵有根树可以进行深度优先遍历(DFS)以及广度优先遍历(BFS)来生成这棵树的 DFS 序以及 BFS 序.两棵不同的树的 DFS 序 ...
- 原 .NET/C# 反射的的性能数据,以及高性能开发建议(反射获取 Attribute 和反射调用方法)
大家都说反射耗性能,但是到底有多耗性能,哪些反射方法更耗性能:这些问题却没有统一的描述. 本文将用数据说明反射各个方法和替代方法的性能差异,并提供一些反射代码的编写建议.为了解决反射的性能问题,你可以 ...
- 刷题总结——火柴排队(NOIP2013)
题目: 题目背景 NOIP2013 提高组 Day1 试题 题目描述 涵涵有两盒火柴,每盒装有 n 根火柴,每根火柴都有一个高度.现在将每盒中的火柴各自排成一列,同一列火柴的高度互不相同,两列火柴之间 ...
- bzoj1225 [HNOI2001] 求正整数
1225: [HNOI2001] 求正整数 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 762 Solved: 313[Submit][Statu ...
- Java程序性能优化之缓冲优化
优化前的代码: package com; import javax.swing.*; import java.awt.*; /** * 使用Eclipse,右键Run As,Java Applet运行 ...
- 【BZOJ2002】弹飞绵羊(LCT)
题意:给定一棵树,要求维护以下操作: 1.删除连接(x,y)的边 2.将(x,y)之间连边 3.询问某点子树大小 对于100%的数据n<=200000,m<=100000 思路:第一道有加 ...