Don't get input from user after getch()

I'm doing something like given below

#include <stdio.h>
#include <ncurses.h>

int main()
{
int ch;
ch = getch();
while( ch != 'E' )
{
if( ch == 65 )
{
char buf[50];
getline( (char **) buf, (int *) 50, stdin);
printw("%s", buff);
}
ch = getch();
}
return 0;
}

getline get failed after getch(), don't know waht is happening.
> getline( (char **) buf, (int *) 50, stdin);
the compiler was gentle enough to tell you that your usage of the function was incorrect, don't cast away error messages.

man getline wrote:
getline() reads an entire line from stream, storing the address of the buffer
containing the text into *lineptr. The buffer is null-terminated and includes
the newline character, if one was found.

If *lineptr is set to NULL and *n is set 0 before the call, then getline() will
allocate a buffer for storing the line. This buffer should be freed by the
user program even if getline() failed.

Alternatively, before calling getline(), *lineptr can contain a pointer to a
malloc-allocated buffer *n bytes in size.

Either you provide a dynamic allocated string, or you left the fuction allocate it for you.


By the way, getline() is from stdio, I don't think that you can mix it with ncurses so freely.
Topic archived. No new replies allowed.