프로그램을 C 언어 문자열 배열에 저장하기위한 프로그램이다.
다음 프로그램을 prg2arr.c 에 저장한다.
#include <stdio.h>
#include <string.h>
int main() {
int c;
char spaces[] = " ";
printf("%s", spaces); puts("char *first[]={" ); printf("%s%s", spaces, spaces); putchar(34);
while( (c= getchar()) != EOF ) {
if( c == '\'' ) { // if it's a single quotation
putchar('\\'); putchar(c);
} else if( c == 34 ) { // if it's a double quotation
putchar('\\'); putchar(c);
} else if( c == '\\') { // if it's a back slash
putchar('\\'); putchar(c);
} else if( c == '\?' ) { // if it's a question mark
putchar('\\'); putchar(c);
} else if( c == '\n') {
putchar(34); putchar(','); putchar(c); printf("%s%s", spaces, spaces); putchar(34);
} else {
putchar(c);
}
}
putchar(34); putchar('\n');
printf("%s", spaces); putchar('}'); putchar(';');
return 0;
}
rem add_path.bat
@echo off
set path=%path%;D:\mingw64\bin
와 같은 간단한 프로그램을 C 문자열 배열로 만들어 보자.
prg2arr < add_path.bat

위의 결과를 C 언어 프로그램의 일부로 복사하여 사용하면 된다.
'C 언어' 카테고리의 다른 글
| C언어 한글 정렬하기 (3) | 2021.01.28 |
|---|---|
| C 언어로 달력 만들기 (0) | 2021.01.24 |
| MINGW64 설치하는 방법 (0) | 2021.01.22 |
| C 언어에서 right 함수 사용 (0) | 2021.01.21 |
| strtof 함수를 이용한 계산기 (0) | 2021.01.21 |
댓글