아래의 소스는

            Visual Studio 2008 Express (Visual C++ 9.0),
            GNU C 3.4.4 (gcc), 
            Borland C++ 5.5 (free)
            Digital Mard (free) 

C 컴파일러에서 한글도 잘 처리됨을 확인하였다.  그러나 Bloodshed Dev-C++ 에서는 gets()에 의한 한글 입력과 printf()에 의한 한글 출력이 되지 않았다.


/*
 *  inputTest.c
 *
 *  Compile:
 *          gcc inputTest.c
 *          dmc inputTest.c
 *          bcc32 inputTest.c
 *          cl inputTest.c
 *
 *  Execute:
 *          inputTest 2
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void printStr(char **);

int main(int argc, char **argv) {
    char temp[80];
    char **str;
    int max;
    int i;

    if (argc != 2) {
        printf("Usage: inputTest <숫자>\n");
        exit(1);
    }

    max = atoi(argv[1]); // 문자열을 수치값으로 변환
    str = (char **)malloc((max+1) * sizeof(char *));

    i=0;
    while (1) {
        printf("%d째 문자열을 입력하세요> ", i+1);
        gets(temp);
        if (temp[0] == '\0')
            break;

        str[i] = (char *)malloc(strlen(temp) + 1);
        strcpy(str[i], temp);
        i++;
        if (i == max) {
            printf("문자열 입력을 완료했습니다.\n");
            break;
        }
    }

    str[i] = 0;
    printStr(str);
    i = 0;
    while (str[i] != 0) {
        free(str[i]);
        ++i;
    }
    free(str);
    return 0;
}

void printStr(char **sp) {
    while (*sp != 0) {
        printf("%s \n", *sp);
        sp++;
    }
}





실행 결과:
프롬프트> inputTest 2
1째 문자열을 입력하세요> 하나
2째 문자열을 입력하세요> 둘
문자열 입력을 완료했습니다.
하나

Posted by Scripter
,