D Programming Language Forums
digitalmars.DShow header Prev. Next
Re: getch() function Digital Mars
Vathix () 2004/05/28 09:05

"Bruno A. Costa" <bruno@codata.com.br> wrote in message
news:c97bq0$18nm$1@digitaldaemon.com...
> Hi,
>
> I'm trying to compile some programs that use the getch() function,
> but they fail to link:
>
> [bruno@localhost D]$ dmd char.d
> gcc char.o -o char -lphobos -lpthread -lm
> char.o(.gnu.linkonce.t_Dmain+0x30): In function `_Dmain':
> : undefined reference to `getch'
> collect2: ld returned 1 exit status
> --- errorlevel 256
>
> Example from dsource.org:
>
> import std.c.stdio;
> import std.string;
>
> void main()
> {
>     char k;
>
>     printf("\nI'm going to ask you to press 10 keys (I promise it's
> painless).\n"
>     "Certain keys don't count, but the whole alphabet is fair game.\n\n");
>
>     for(int i=0; i<10; i++)
>     {
>         printf("Press key: %d\t", i);
>         k = getch();
>         printf("[%c]\t", k);            /* print the character pressed */
>         printf("[%d]\n", cast(int) k);  /* print ASCII code for key */
>     }
>     printf("\nThe End.\n\n");
> }
>
> I'm using dmd-0.90 in a Fedora Linux Core 2, gcc version 3.3.3
>
> Hints???
>
>
> Thanks,
> Bruno.


It's a Windows function (or Linux if you're using some term library). Use
getchar(). getch() returns immediatly when a key is pressed, but getchar()
waits until return is pressed and is portable.


Next Prev. Article List Reply Crosspost Forward   Favorite


PHP News Reader v2.6.4   SourceForge.net