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');
}
Run Code Online (Sandbox Code Playgroud)
这是包含以下内容的代码部分 getch()
当我尝试在联机编译器中运行此代码时,出现以下错误:未定义对getch
collect2的引用:错误:1d返回1退出状态
如何解决这个问题?...请帮助
标准 C库中没有getch函数,它仅存在于Windows中,并且因为它不是标准函数,所以其真实名称是(请注意下划线)。根据错误消息判断,您的在线编译器使用GCC,并且很可能在Linux环境中使用GCC,因此没有(或)功能。_getchgetch_getch
如果要便携式使用,或者用fgetc或getcgetchar(但请注意,这些函数返回int)。