C注释转换至CPP注释
来源:互联网 发布:程序员之死女主角 编辑:程序博客网 时间:2024/06/05 07:05
convernt.h 如下:
#ifndef __CONVERNT_CTOCPP_H__
#define __CONVERNT_CTOCPP_H__
#include<stdio.h>
enum {
NULLSTATUS,CSTATUS,CPPSTATUS,EOFSTATUS
};
void convernctocpp();
void convernt_ctocpp(FILE *ifp, FILE *ofp);
void do_null_status(FILE *ifp, FILE *ofp);
void do_c_status(FILE *ifp, FILE *ofp);
void do_cpp_status(FILE *ifp, FILE *ofp);
#endif
--------------------------------------------------------------------------------
convernt.c
代码如下:
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include"convernt.h"
int status = NULLSTATUS;
void do_null_status(FILE *ifp, FILE *ofp){
int c = fgetc(ifp);
switch (c)
{
case '/':{
int d = fgetc(ifp);
switch (d)
{
case'*':
fputc('/', ofp);
fputc('/', ofp);
status = CSTATUS;
break;
case '/': fputc('/',ofp);
fputc('/',ofp);
status = CPPSTATUS;
break;
case EOF:
status = EOFSTATUS;
break;
default:
fputc(c, ofp);
ungetc(d, ifp);
status = NULLSTATUS;
break;
}
}break;
case EOF:status = EOFSTATUS;
break;
default:
fputc(c, ofp);
status = NULLSTATUS;
break;
}
}
void do_c_status(FILE *ifp, FILE *ofp){
int c = fgetc(ifp);
switch (c)
{
case '*':
{
int d = fgetc(ifp);
switch (d)
{
case '/':
fputc('\n', ofp);
status = NULLSTATUS;
break;
default:
fputc(c, ofp);
ungetc(d, ifp);
status = CSTATUS;
break;
}
break;
}
case '\n':
fputc(c, ofp);
fputc('/', ofp);
fputc('/', ofp);
status = CSTATUS;
break;
case EOF:
status = EOFSTATUS;
break;
default:
fputc(c, ofp);
status = CSTATUS;
break;
}
}
void do_cpp_status(FILE *ifp, FILE *ofp){
int c = fgetc(ifp);
if (c != '\n'){
fputc(c,ofp);
status = CPPSTATUS;
}
else
{
fputc(c,ofp);
status = NULLSTATUS;
}
}
static void convent_work(FILE *ifp, FILE *ofp){
while (status != EOFSTATUS){
switch (status)
{
case NULLSTATUS: do_null_status(ifp, ofp);
break;
case CSTATUS: do_c_status(ifp, ofp);
break;
case CPPSTATUS: do_cpp_status(ifp, ofp);
break;
case EOFSTATUS:
break;
default:
break;
}
}
}
void convernctocpp(){
FILE *ifp = fopen("input.txt", "r");
FILE *ofp = fopen("output.txt","w");
if (ifp == NULL || ofp == NULL){
printf("Error \n");
return;
}
convent_work(ifp, ofp);
fclose(ifp);
fclose(ofp);
}
-------------------------------------------------------------------------
测试程序
main.c
#include<windows.h>
#include<stdio.h>
#include"convernt.h"
int main(){
convernctocpp();
system("pause");
return 0;
}
运行结果
- C注释转换至CPP注释
- c注释转换为cpp注释
- C和CPP注释转换
- c的注释转换成cpp
- C到CPP的注释转换
- 把c语言注释转换为cpp注释
- IO注释转换---CPP风格
- 注释转换<C注释-->C++注释>
- 将c风格的注释转换成cpp风格
- c语言注释转换(c注释转换成c++注释)
- c/c++注释转换
- 【C语言】注释转换
- C语言 注释转换
- 【C语言】注释转换
- C/C++注释转换
- 注释转换C->C++
- 注释转换 (将C注释转换为C++注释)
- 注释转换 续 (C++注释转换为C注释)
- 14、ES6 for...of循环
- 深度函数式神经网络
- discuz X3.4的最新版QQ互联插件配置教程
- 内核中的中断函数request_irq()
- 【安全牛学习笔记】skipfish
- C注释转换至CPP注释
- hdu 5213 Lucky (莫队+容斥)
- webpack使用
- (笔记) Linux环境下的图形系统简介(X window)
- 由request_irq()函数引发对中断的理解
- Java创建子类对象时的内存分配
- java作业
- C# 进程启动
- 创建一个slider UI,并将其呈现在世界坐标作为血条