首先我們應該知道,在c語言中 ,編譯器預設的注釋風格是 /* .........*/ ,而在c++中 ,編譯器預設的注釋風格是 // ....... 注釋一行。這兩種注釋風格是可以互相轉換的。
下面給上轉換後的結果:
對該過程進行分析:
程式**如下:
commentconvert.h
commentconvert.c#ifndef __commeent_convert_h__
#define __commeent_convert_h__
#include #include enum state
;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//__commeent_convert_h__
tsst.c#define _crt_secure_no_warnings
#include "commentconvert.h"
void donulstate(file* pfin, file* pfout, enum state* s)
} break;
case eof:
*s = end_state;//檔案結束,轉換至結束狀態
break;
default:
fputc(first, pfout);
break; }}
void docstate(file* pfin, file* pfout, enum state* s)
else
}break;
case '*':
fputc(first, pfout);
ungetc(second, pfin);
break;
default:
fputc(first, pfout);
fputc(second, pfout);
break;
} }break;
case '\n'://多行注釋的處理
fputc(first, pfout);
fputc('/', pfout);
fputc('/', pfout);
break;
case eof://檔案結束,轉換至無狀態
*s = end_state;
break;
default:
fputc(first, pfout);
break; }}
void docppstate(file* pfin, file* pfout, enum state* s)
}
在資料夾中可以找到該程式,該程式的執行結果已經在上面給出:#define _crt_secure_no_warnings
#include "commentconvert.h"
void commentconvert(file* pfin, file* pfout) }}
void test()
pfout = fopen("output.c", "w");
if (pfout == null)
commentconvert(pfin, pfout);
fclose(pfin);
fclose(pfout);
}int main()
注釋轉換 (C語言注釋轉換為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.連續注釋問題 6.連續的 問題 7.c 注釋問題 ...
c語言 注釋轉換
注釋轉換。對於乙個專案有多個人來寫 如果每個人的 注釋風格不一樣,有的人要用c注釋風格,有的人用c 注釋風格這就導致了,對於閱讀源 的人的不方便的問題。因此才會出現注釋轉換的這個東西。本注釋轉換將所有程式的注釋全部轉換成c 的注釋風格。首先列出所有可能出現的情況 1.一般情況 int num 0 i...
C語言 注釋轉換
如下 標頭檔案 commentconvert.h ifndef comment convert h define comment convert h define crt secure no warnings 1 define file name 0 include include include ...