struct node
{
int data;
struct node *next;
} *start=NULL;
void create()
{
char ch;
do
{
struct node *new_node,*current;
new_node = (struct node *)malloc(sizeof(struct node));
printf("\nEnter the data : ");
scanf("%d",&new_node->data);
new_node->next = NULL;
if(start == NULL)
{
start = new_node;
current = new_node;
}
else
{
current->next = new_node;
current = new_node;
}
printf("nDo you want to creat another : ");
ch = getch();
} while(ch!='n');
}
This is the part of the code which contains getch()
When I try to run this code in an online compiler I am getting this error:
undefined reference to getch
collect2: error: 1d returned 1 exit status
How to solve this problem?...Please help
There is no getch
function in the standard C library, it only exist in Windows, and because it's not a standard function its real name is _getch
(note the leading underscore). Judging by the error message your online compiler uses GCC, and most likely in a Linux environment, so no getch
(or _getch
) function.
If you want to be portable use fgetc
or getc
instead, or getchar
(but note that those functions returns an int
).
There is a getch in linux, but in a library
#include <ncurses/curses.h>
See http://linux.die.net/man/3/getch for more detail. If the online compiler works under linux, and get the ncurses library, this will be work !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With