iconv 다시질문

lengbo의 이미지

아무래도 해결이 안나서요

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

int main()
{
char * str = "안녕하세요 마스터카드입니다.";

char * out = malloc(sizeof(char)*1000);
char * out_p = out;
memset((void *)out,0, (size_t)1000);

printf("%s%d 글자출력\n",str, strlen(str));

iconv_t cd = iconv_open("ISO-2022-KR", "EUC-KR");

if ((int)cd <= 0) {
printf("에러\n");
exit(0);
}

size_t inbytesleft = strlen(str);
size_t outbytesleft = 999;

size_t st = iconv(cd, &str, &inbytesleft, &out_p, &outbytesleft);
printf("%s\n",out);
iconv_close(cd);
return 0;
}

여기서 결과가
)C>H3gGO<<?d 86=EMD+5e@T4O4Y.
로 나오는데.

이걸 다시 한글로 바꾸려고 아래와 같이 했는데

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

int main()
{
char * str = ")C>H3gGO<<?d 86=EMD+5e@T4O4Y.";

char * out = malloc(sizeof(char)*1000);
char * out_p = out;
memset((void *)out,0, (size_t)1000);

printf("%s%d 글자출력\n",str, strlen(str));

iconv_t cd = iconv_open("EUC-KR", "ISO-2022-KR");

if ((int)cd <= 0) {
printf("에러\n");
exit(0);
}

size_t inbytesleft = strlen(str);
size_t outbytesleft = 999;

size_t st = iconv(cd, &str, &inbytesleft, &out_p, &outbytesleft);
printf("%s\n",out);
iconv_close(cd);
return 0;
}

결과는
)C>H3gGO<<?d 86=EMD+5e@T4O4Y.
로 똑같이 나오네요.

아래 정태영님께서 말씀하신대로 ISO-2022-KR 케릭터셋으로 인식하지 못하는거 같은데요
어떻게 해야 하는건가요?

progcom의 이미지

표현되는 그대로 입력하면 된다고 생각하시는 데서 문제가 있는겁니다.

~/work%./a.out | hd
00000000  1b 24 29 43 0e 3e 48 33  67 47 4f 3c 3c 3f 64 0f  |.$)C.>H3gGO<<?d.|
00000010  20 0e 38 36 3d 3a 45 4d  44 2b 35 65 40 54 34 4f  | .86=:EMD+5e@T4O|
00000020  34 59 0f 2e 0a                                    |4Y...|
00000025

보시다시피 밖으로 표시되지 않는 코드가 존재합니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.