注释转换
来源:互联网 发布:mac软件下载网站排名 编辑:程序博客网 时间:2024/06/08 03:18
//convert.h#ifndef __CONVERT_H__#define __CONVERT_H__#include<stdio.h>#include<stdlib.h>#define INPUTFILENAME "input.c" #define OUTPUTFILENAME "output.c"typedef enum CONVERT_START{ NUL_START, C_START, CPP_START, EOF_START}StateType;void CommentConver();void ConvertWork(FILE *r, FILE *w); void DoCState(FILE *r, FILE *w);void DoNullState(FILE *r, FILE *w); void DoCppState(FILE *r, FILE *w);#endif
//main.c#define _CRT_SECURE_NO_WARNINGS 1#include<stdio.h>#include"convert.h"StateType state;void do_NUL_State(FILE *r, FILE *w){ int f = fgetc(r); int s; switch (f) { case '/': s = fgetc(r); if (s == '*') { fputc('/', w); fputc('/', w); state = C_START; } else if(s == '/') { fputc('/', w); fputc('/', w); state = CPP_START; } else { ungetc(f, w); ungetc(s, w); } break; case EOF: fputc(f, w); state = EOF_START; break; default: fputc(f, w); break; }}void do_C_State(FILE *r, FILE *w){ int f = fgetc(r); int s = 0; switch (f) { case'*': s = fgetc(r); if (s == '/') { int t = fgetc(r); state = NUL_START; if (t != '\n') { fputc('\n', w); ungetc(t, r); } else { fputc(t, w); } } else { fputc(f, w); ungetc(s, r); } break; case '\n': fputc(f, w); fputc('/', w); fputc('/', w); break; case EOF: fputc(f, w); state = EOF_START; break; default: fputc(f, w); break; }}void do_CPP_State(FILE *r, FILE *w) { int f = fgetc(r); switch (f) { case'\n': fputc(f, w); state = NUL_START; break; case EOF: fputc(f, w); state = EOF_START; break; default: fputc(f, w); break; }}void ConvertWork(FILE *r, FILE *w){ state = NUL_START; while (state != EOF_START) { switch (state) { case NUL_START: do_NUL_State(r, w); break; case C_START: do_C_State(r, w); break; case CPP_START: do_CPP_State(r, w); break; default: break; } }}void CommentConvert(){ FILE *pw = NULL; FILE *pr = fopen(INPUTFILENAME, "r"); if (pr == NULL) { perror("open file for read"); exit(EXIT_FAILURE); } pw = fopen(OUTPUTFILENAME, "w"); if (pw == NULL) { fclose(pr); perror("open file for write"); exit(EXIT_FAILURE); } ConvertWork(pr, pw); fclose(pr); fclose(pw);}
//test.c#define _CRT_SECURE_NO_WARNINGS 1#include<stdio.h>#include<windows.h>#include"convert.h"void test(){ CommentConvert();}int main(){ test(); system("pause"); return 0;}
测试用例:
// this is maomaochong/* int i = 0; *//* int j = 10 */int k = 3;int n = 20;/*int i = 0;int j = 20;int k = 250;*/int q = 9527;/***//* int z = 7748258; */ /*int b=94250;*/// /*dsklfjdasl;fdsf;ldsfds*/
阅读全文
0 0
- 注释转换
- 注释转换
- 注释转换
- 注释转换
- 注释转换
- 注释转换
- 注释转换
- 注释转换
- 注释转换
- 注释转换
- 注释转换
- 注释转换
- 注释转换
- 注释转换
- 注释转换
- 注释转换
- 注释转换
- 注释转换
- [数学杂题]BZOJ 2111—— [ZJOI2010]Perm 排列计数
- guava做本地缓存
- annotation-@RequestBody-接收前端传来的json
- 关于onclick = “函数()”中不能调用window.onload = function(){}中调用function 函数(){}
- pandas---Series基础使用
- 注释转换
- 统计学习方法(第三章)k近邻算法
- 初级web api的设计(二)——防重放攻击
- 神经网络 tensorflow教程 2.2 下载MNIST 数据集 (自动版)
- 统计学习方法总结、应用对比
- 《Android学习笔记》利用Application操作全局变量
- 计算一下pytorch中Resnet34模型前传一次所需要的时间
- tf.reshape()的用法与理解
- 写出程序的输出结果