C언어 프로그램을 HTML 형식으로 만드는 프로그램이다.
다음 프로그램을 c2html.c 로 저정하고 compile 한다.
#include <stdio.h>
char first[ ] = "<div style=\"background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\"><pre style=\"margin: 0; line-height: 125%\">";
char lb[]="<" ;
char rb[]=">" ;
char amp[]="&" ;
char sq[]="'" ;
char dq[]=""" ;
char nl[]="</span>\n<span>" ;
char last[ ] = "</code></pre>\n</div>";
int main( ) {
int c;
printf("%s\n", first);
printf("<span>");
while( (c=getchar( )) != EOF ) {
if( c == '<' ) printf("%s", lb); /* < */
else if( c == '>' ) printf("%s", rb); /* > */
else if( c == '&' ) printf("%s", amp); /* ampersand */
else if( c == 39 ) printf("%s", sq); /* single quote */
else if( c == 34 ) printf("%s", dq); /* double quote */
else if( c == '\n' ) printf("%s", nl); /* new line */
else
putchar(c);
}
puts( last );
return 0;
}
그리고 test.c 에는 다음 프로그램을 작성한다.
#include <stdio.h>
int main() {
puts("Hello world\n");
return 0;
}
c2html < test.c 를 실행한다. 이 경우 코맨드 창에 아래와 같이 출력이 된다.

c2html < test.c > test.html 를 실행하면 코맨드 창에 아래와 같이 출력이 되지 않고, test.html에기록이 된다.
test.html을 열어보면 아래와 같이 코드가 HTML로 보기 좋게 표현됨을 알 수 있다.
#include <stdio.h>
int main() {
puts("Hello world\n");
return 0;
}
'C 언어' 카테고리의 다른 글
| C 언어를 이용한 계산기 (2) (0) | 2021.01.20 |
|---|---|
| C 언어를 이용한 계산기 (0) | 2021.01.16 |
| Json 파일을 자막 파일인 srt로 변경 (0) | 2021.01.02 |
| C언어로 자막 파일 수정하기 (0) | 2021.01.02 |
| C언어를 이용해서 Log 함수 계산하기 (0) | 2021.01.01 |
댓글