C언어로 만든 코드 들여쓰기 프로그램이다.
#include <stdio.h>
int main(void) {
int c;
int indented_already = 0;
int indent = 0;
int quote = 0;
while( ( c = getchar()) != EOF ) {
if( ( c ==' ' || c == '\t' ) && indented_already == 0)
continue;
if( c == '}' ) {
if( quote != 1 ) indent--;
}
if( ( c!= ' ' && c!= '\t' ) && indented_already == 0 ) {
for(int i = 0; i < indent; i++ ) {
printf(" ");
}
}
putchar(c);
indented_already = 1;
if( c == '"' ) {
quote = 1 - quote;
}
else
if( c == '{' ) {
if( quote != 1 ) indent++;
}
else
if( c == '\n' ) {
indented_already = 0;
}
}
return 0;
}
'C 언어' 카테고리의 다른 글
| C언어로 만든 Youtube 플레이리스트 추출 프로그램 (0) | 2021.09.12 |
|---|---|
| C 언어로 string Replace 함수 만들기 (2) (0) | 2021.09.09 |
| C 언어로 간단한 게임 만들기 (0) | 2021.08.16 |
| C 언어로 숫자 야구 게임 만들기 (0) | 2021.07.15 |
| C 언어에서 코맨드라인 인수 (0) | 2021.07.01 |
댓글