c/c++注释转换函数
来源:互联网 发布:wireshark过滤端口 编辑:程序博客网 时间:2024/06/05 08:10
题目:要求将下列的注释全部都转换成c++中的的注释,也就是//注释
// 1.一般情况
/* 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.连续注释问题
/**//**/
// 6.连续的**/问题
/***/
// 7.C++注释问题
// /*xxxxxxxxxxxx*/
结果:
// 1.一般情况
// 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.连续注释问题
//
//
// 6.连续的**/问题
//*
// 7.C++注释问题
// /*xxxxxxxxxxxx*/
代码如下:
(1).头文件
#pragma once #define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<string.h>#include<assert.h>enum State{NUL_STATE,C_STATE,CPP_STATE,END_STATE};void CommentConvert();void DoCommentConvert(FILE *Input, FILE * Output );void DoNulComment(FILE *Input, FILE * Output ,enum State * state);void DoCComment(FILE *Input, FILE * Output ,enum State * state);void DoCppComment(FILE *Input, FILE * Output ,enum State * state);(2).函数实现:
#include"CommentConverce.h"void CommentConvert(){FILE *pfin = NULL;FILE *pfout = NULL;pfin = fopen("input.c","r");if (NULL == pfin){perror("input.c");exit(EXIT_FAILURE);}pfout = fopen("output.c","w");if (NULL == pfin){perror("output.c");fclose(pfin);exit(EXIT_FAILURE);}DoCommentConvert(pfin, pfout);printf("转换完成!\n");fclose(pfin);fclose(pfout);}void DoCommentConvert(FILE *Input, FILE * Output ){enum State state = NUL_STATE;while (END_STATE != state ){switch (state){case NUL_STATE:DoNulComment(Input, Output, &state);break;case C_STATE:DoCComment(Input, Output, &state);break;case CPP_STATE:DoCppComment(Input, Output, &state);break;default:break;}}}void DoNulComment(FILE *Input, FILE * Output ,enum State * state){int first = 0;first = fgetc(Input);switch (first){case '/':{int second = 0;second = fgetc(Input);switch (second){case '*':*state = C_STATE;fputc('/', Output);fputc('/', Output);break;case '/':*state = CPP_STATE;fputc('/', Output);fputc('/', Output);break;default:fputc(second, Output);break;}}break;case EOF:*state = END_STATE;break;default:fputc(first, Output);break;}}void DoCppComment(FILE *Input, FILE * Output ,enum State * state){int first = 0;first = fgetc(Input);switch (first){case '\n':*state = NUL_STATE;fputc('\n', Output);break;case EOF:*state = END_STATE;default:fputc(first, Output);break;}}void DoCComment(FILE *Input, FILE * Output ,enum State * state){int first = 0;first = fgetc(Input);switch (first){case'\n':fputc(first, Output);fputc('/',Output);fputc('/',Output);break;case '*':{int second = 0;second = fgetc(Input);switch (second){case '/'://fputc('\n' , Output);{int third = 0;third = fgetc(Input);if ('\n' != third){fputc('\n',Output);}ungetc(third,Input);*state = NUL_STATE;break;}case '*':ungetc(second, Input);fputc(first,Output);break;default:fputc(first, Output);fputc(second, Output);break;}}break; //我擦,少了个break,搞死人呢。default:fputc(first, Output);break;}}(3).主函数
#include"CommentConverce.h"int main(){CommentConvert();system("pause");return 0;}
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注释转换为C++注释)
- OPENCV入门教程十三:GaussianBlur高斯平滑
- NSDate
- Java7并发编程--4.1、创建线程执行器
- win7 64位 Caffe+Cuda6.5+Opencv3.10+Boost1.56配置
- POJ 1088 滑雪(简单DFS+dp)
- c/c++注释转换函数
- Mathematica数据处理(5)--Plot
- 初学C语言:斐波那契数列(求前n项和)
- iOS——navigationBar色差问题
- 【Leetcode】143. Reorder List - 链表重排序
- 回型矩阵
- 提升架构能力
- IM模块-文本添加表情
- iOS开发 - 键盘的收起