[注释转化]C语言注释转换为C++语言注释
2017-07-29 20:08
337 查看
CommentCovnert.h
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*/
#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*/
相关文章推荐
- 【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++注释 )
- C语言的注释与C++注释的转换
- 实现c语言注释转换为c++注释
- C语言注释与C++注释的相互转换
- 【C语言】C语言注释转换成C++注释。
- C语言注释转换为c++的注释
- 注释转换(c语言->c++)
- 实现C++注释转换为标准C语言注释