說明:c注釋:
/*注釋內容*/
cpp注釋:
//注釋內容
1.標頭檔案
commentconvert.h
2.原始檔 commentconvert.c#ifndef __comment_convert_h__
#define __comment_convert_h__
#include #include enum state //4種狀態,可以切換,轉換關係如上圖
;void donulstate(file*pfin, file* pfout, enum state* state);
void docstate(file*pfin, file* pfout, enum state* state);
void docppstate(file*pfin, file* pfout, enum state* state);
#endif //__comment_convert_h__
3.測試區 test.c#include "commentconvert.h"
void donulstate(file* pfin, file* pfout, enum state* s)
} break;
case eof:
*s = end_state;
break;
default:
fputc(first, pfout);
*s = nul_state;
donulstate(pfin, pfout, &s);
break; }}
void docstate(file*pfin, file* pfout, enum state* s)
else
*s = nul_state;
donulstate(pfin, pfout, &s);
break;
}default:
fputc(first, pfout);
fputc(second, pfout);
*s = c_state;
docstate(pfin, pfout, &s);
break;
}} break; //執行完返回
case '\n':
fputc('\n', pfout);
fputc('/', pfout);
fputc('/', pfout);
*s = c_state;
docstate(pfin, pfout, &s);
break;
default:
fputc(first, pfout);
*s = c_state;
docstate(pfin, pfout, &s); //迴圈拷貝正常**
break; }}
void docppstate(file*pfin,file* pfout, enum state* s)
}
4.自己建立的檔案,input.c內容如下#include "commentconvert.h"
void test()
file* pfout = fopen("output.c", "w");
if (pfout == null)
donulstate(pfin, pfout, &state);
fclose(pfin);
fclose(pfout);
}int main()
5.執行後,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;/****xx*/
// 4.多行注釋問題
/*int i=0;
int j = 0;
int k = 0;
*/int k = 0;
// 5.連續注釋問題
/*a*//*b*/
// 6.連續的**/問題
/******/
// 7.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;/****xx
// 4.多行注釋問題
////int i=0;
//int j = 0;
//int k = 0;
//int k = 0;
// 5.連續注釋問題
//a//b
// 6.連續的**/問題
//****
// 7.c++注釋問題
// /**************/
注釋轉換 c注釋 c 注釋
本專案基於乙個狀態機的思想,每次處理完成之後通過狀態的裝換繼續處理後邊的內容。另外,利用各類的檔案操作函式,實現將將c風格的注釋裝換成c 風格的注釋的乙個簡單功能。大概如下圖 什麼是狀態機?在本專案中,會用到四種狀態,既空狀態 正常 區 c注釋狀態 c風格注釋區 c 注釋狀態 c 風格注釋區 檔案結...
注釋轉換(C注釋轉換為c 注釋)
對於注釋轉換首先給出我的測試圖 由圖可以看出將左邊的c語言注釋轉換為右邊c 注釋就是注釋轉換 首先說明一下轉換思想方法 1.建立兩個檔案input.c和output.c,input.c裡面用來讀取c語言的注釋,output.c裡面儲存轉換成為c 的注釋,中間的轉換過程就是 完成,當然檔案名字和作用自...
注釋轉換C 注釋》
注意 中所用到的fopen,fwrite,fread等檔案操作函式在通訊錄檔案流部落格中做了介 紹 ungetc 函式是將從檔案中讀取的乙個字元還回到緩衝區,即檔案中去 分析思路圖 分析思路圖 自定義標頭檔案部分 ifndef comment convert h define comment con...