[注释转化]C语言注释转换为C++语言注释
来源:互联网 发布:unity3d ar ios 编辑:程序博客网 时间:2024/06/05 09:47
CommentCovnert.h
#ifndef __COMMENT_CONVERT_H__#define __COMMENT_CONVERT_H__#include <stdio.h>#include <stdlib.h>enum STATE{END_STATE,NUL_STATE,C_STATE,CPP_STATE};void DoNulState(FILE* pfin, FILE* pfout, enum STATE* s);void DoCState(FILE* pfin, FILE* pfout, enum STATE* s);void DoCppState(FILE* pfin, FILE* pfout, enum STATE* s);#endif //__COMMENT_CONVERT_H__
CommentConvert.c#include "CommentConvert.h"void DoNulState(FILE* pfin, FILE* pfout, enum STATE* s){int first = 0;int second = 0;first = fgetc(pfin);switch (first){case '/':{second = fgetc(pfin);switch (second){case '/':fputc(first, pfout);fputc(second, pfout);*s = CPP_STATE;break;case '*':fputc(first, pfout);fputc('/', pfout);*s = C_STATE;break;default:fputc(first, pfout);fputc(second, pfout);break;}}break;case EOF:*s = END_STATE;break;default:fputc(first, pfout);*s = NUL_STATE;break;}}void DoCState(FILE* pfin, FILE* pfout, enum STATE* s){int first = 0;int second = 0;int third = 0;first = fgetc(pfin);switch (first){case '*':{second = fgetc(pfin);switch (second){case '/':{third = fgetc(pfin);if (third == '\n'){fputc(third, pfout);}else{ungetc(third, pfin);fputc('\n', pfout);}*s = NUL_STATE;}break;case '*':{ungetc(second, pfin);fputc(first, pfout);}break;default:{ fputc(first, pfout); fputc(second, pfout);}break;}break;case EOF:*s = END_STATE;break;case '\n': fputc(first, pfout);fputc('/', pfout);fputc('/', pfout);break;default:fputc(first, pfout);}}}void DoCppState(FILE* pfin, FILE* pfout, enum STATE* s){int first = 0;int second = 0;first = fgetc(pfin);switch (first){case '\n':fputc(first, pfout);*s = NUL_STATE;break;case EOF:*s = END_STATE;break;default:fputc(first, pfout);break;}}
test.c#define _CRT_SECURE_NO_WARNINGS 1#include "CommentConvert.h"//注释转化test(){enum STATE state = NUL_STATE;FILE* fin = NULL;FILE* fout = NULL;fin = fopen("input.c", "r");if (fin == NULL){perror("fopen input");exit(EXIT_FAILURE);}fout = fopen("output.c", "w");if (fout == NULL){perror("fopen output");exit(EXIT_FAILURE);}while (state != END_STATE){switch (state){case NUL_STATE:DoNulState(fin, fout, &state);break;case C_STATE:DoCState(fin, fout, &state);break;case CPP_STATE:DoCppState(fin, fout, &state);break;default:break;}}fclose(fin);fclose(fout);}int main(){test();system("pause:");return 0;}
input.c
// 1.一般情况
int num = 0;
/* int i = 0; */
// 2.换行问题
/* int i = 0; */int j = 0;
/* int i = 0; */
int j = 0;
// 3.匹配问题
/*int i = 0;/*xxxxx*/
// 4.多行注释问题
/*
int i=0;
int j = 0;
int k = 0;
*/int k = 0;
// 5.连续注释问题
/*a*//*b*/
// 6.连续的**/问题
/***/
// 7.C++注释问题
// /*xxxxxxxxxxxx*/
output.c
// 1.一般情况
int num = 0;
// int i = 0;
// 2.换行问题
// int i = 0;
int j = 0;
// int i = 0;
int j = 0;
// 3.匹配问题
//int i = 0;/*xxxxx
// 4.多行注释问题
//
//int i=0;
//int j = 0;
//int k = 0;
//
int k = 0;
// 5.连续注释问题
//a
//b
// 6.连续的**/问题
//*
// 7.C++注释问题
// /*xxxxxxxxxxxx*/
阅读全文
0 0
- [注释转化]C语言注释转换为C++语言注释
- C++注释转化为C语言注释
- C语言注释转化为C++注释
- C语言:C语言注释转换C++,注释转化项目C-->C++注释
- 【C语言】注释转换
- C语言 注释转换
- 【C语言】注释转换
- [数据结构]c++注释转化为c语言注释
- 小项目-C语言注释转化为C++注释
- 【C语言】注释转换 ——C注释转换为标准C++语言注释
- c语言注释转换(c注释转换成c++注释)
- C语言注释转换为c++的注释
- 实现c语言注释转换为c++注释
- 将C语言注释转换为C++注释
- 将C语言注释转换为c++注释
- 把c语言注释转换为cpp注释
- C++注释转换成C语言注释
- c语言注释转换成c++注释
- 循环结构
- (转)为了快 0.00007 秒,有家交易公司花 1400 万美元买了块地
- 用Java代码实现改变一个文本中的内容,即将一个文本里的内容修改内容,并存储到另一个文本中
- 编程练习——顺时针打印矩阵
- 【CSS 基础】01 概述
- [注释转化]C语言注释转换为C++语言注释
- epoll和select
- hdu 1564 Play a game
- Numpy入门学习之(三) 数组、矩阵基本操作
- PHP基础教程-05 注释
- [PAT乙级]1042. 字符统计(20)
- 7月又将逝去
- springMVC总结二
- 学习使用github建立个人网站