compile time error with getch() #2

  • Follow


Hi,
     I used getch() in my program, but when i compiled it, it showed
me an error message like

                      undefined reference to stdscr
                      undefined reference to wgetch
this is my sample program

#include<curses.h>
int main()
{
   char s[10];
   int i;
   for(i=0;i<10;i++)
    {
        scanf("%c",&s[i]);
        getch();
    }
  for(i=0;i<10;i++)
   printf("%c",s[i]);
}

what wrong in this code.
0
Reply sreekanthtou (10) 10/21/2009 5:57:31 AM

In article 
<dab3851e-1911-4cf6-bd47-cd6a6ce2af7d@t11g2000prh.googlegroups.com>,
 rainbow <sreekanthtou@gmail.com> wrote:

> Hi,
>      I used getch() in my program, but when i compiled it, it showed
> me an error message like
> 
>                       undefined reference to stdscr
>                       undefined reference to wgetch

Check the man page to see if you have to link with a library, e.g. 
-lcurses.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
0
Reply barmar (5627) 10/21/2009 6:21:47 AM


rainbow wrote:
> Hi,
>      I used getch() in my program, but when i compiled it, it showed
> me an error message like
> 
>                       undefined reference to stdscr
>                       undefined reference to wgetch
> this is my sample program
> 
> #include<curses.h>
> int main()
> {
>    char s[10];
>    int i;
>    for(i=0;i<10;i++)
>     {
>         scanf("%c",&s[i]);
>         getch();
>     }
>   for(i=0;i<10;i++)
>    printf("%c",s[i]);
> }
> 
> what wrong in this code.

Well, is getch() what you want there? What are you trying to accomplish, 
exactly? The reason that you are getting link errors is, as Barry 
indicated, that you are referring to a function in the curses library 
but are presumably forgetting to link with that library.

Could you use getchar() instead? That function is in stdio.h, along with 
printf() and scanf(), so you want to include it anyway for those 
functions. Those are all in the standard library, so you wont have to 
link with any extra libraries.


Bjarni
-- 

                        INFORMATION WANTS TO BE FREE
0
Reply bjarni (115) 10/21/2009 11:54:50 AM

2 Replies
55 Views

(page loaded in 0.104 seconds)

Similiar Articles:













7/16/2012 5:03:21 AM


Reply: