getche() 함수 를 gcc에서도 사용하고 싶은데요...

khaic0c0의 이미지

#include <conio.h>
#include <stdio.h>

int main(void)
{
        int ch;
        printf( "enter a charcter: " );
        ch = getche();
        printf( "\nIts ASCII code is %d",ch );

        return 0;
}

이와 같은 소스를 gcc 로 컴파일 했을때 conio.h 를 찾을수 없다고 합니다.
getche() 함수를 사용하기위해서 conio.h 헤더파일을 include 한것인데
gcc 에는 conio.h 가 없나 봅니다.

위 소스를 gcc 에서도 돌아가게 하고 싶은데 어떻게 하면 좋을까요?
getche() 를 대채할수 있는 함수가 뭐가 있을지 궁금합니다.

man 페이지를 참고해봤는데...영어를 잘 읽을수가 없어 이해가 안됩니다.
간단하면 그나마 이게 뭔지라도 볼수 있을텐데...잘 몰라서 이렇게 질문드립니다.

이거 안되면....vc++ 깔아서 실습 해야 될듯 한대.. 에효..
현재 console 만 깔려서 카일릭스? 로도 해볼수 없는거 같은데...
다른 컴파일을 이용하는 방법말고 저 함수를 대채 할수 있는거였으면 하내요..

답변 주시면 감사하겠씁니다.

은빛연어의 이미지

#include <stdio.h>

main()
{
     char buffer[128] = {0};

     gets(buffer);

     printf("[%s]\n", buffer);

}

위의 방법은 문자열을 입력받을때 간편하게 쓸수 있쪄...

아래는 하나의 문자를 입력받아서 처리하는 예입니다.

#include <stdio.h>

main()
{
     int ch;
     char aaa;

     initscr();

     /*for문으로 돌면서 배열에다가 넣어두 되죠.. ^^*/
     ch = getch();
     aaa = c;

     printf("[%c][%c]\n", ch, aaa);

     endwin();
}

gcc -o test test.c -lcurses로 라이브러리를 추가해야함도ㅑ... 
이유는 curses를 참조하세요~
khaic0c0의 이미지

[c@localhost 04_june]$ gcc -o get get.c
/tmp/ccE54B0i.o(.text+0x36): In function `main':
: the `gets' function is dangerous and should not be used.

이와같은 에러가 나내여...
소스는 아래와 같이 했구요...

#include <stdio.h>

int main(void)
{
        char buffer[128] = {0};
        gets(buffer);
        printf( "[%s]\n",buffer );

        return 0;
}

어디가 잘못된거요?
단순히 경고 수준일까요?

컴파일은 되서 실행파일은 생겼거든요...

그리고 처음 보는 함수에 대해서 궁금한게 있는데요...
initscr(); 이건 단순히 화면은 지우는 효과인가요?
endwin 이 함수는 뭐할때 사용하나요?.. ^^;

man 페이지 영어라 잘 모르겠어요...

어딜 가든 필요한 인간되자~~ :-)

은빛연어의 이미지

gets에서 컴파일시에 메시지가 나오는거는 아마도 sun과 linux에서의 라이브러리가 약간씩 차이가 나기 때문인듯...
man page를 참조하심이 젤 확실한데... 한글 맨페이지도 있슴도ㅑ...
아니면... 검색엔진으로 고생하심이... ^^

그리고 curses는 터미널을 제어하기 위해서 제공되는 라이브러리인데 getch는 이 라이브러리중에서 하나죠.. 따라서 터미널 제어를 시작한다는 의미로 initscr함수를 사용하고 터미널 제어를 마칠때 endwin()함수를 사용하져...
만약 이것을 무시하고 그냥 getch를 쓰면 코아가 납니다.. ^^

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.