在TurboC++中,我可以使用getch()函数conio.h.但是在Linux中,gcc没有提供conio.h.我怎样才能获得功能getch()?
我正在Windows中制作一个小型Haskell游戏,我希望每次用户按下一个键时都会响应.因为getChar 奇怪的行为在Windows上,我用FFI以访问getch中conio.h,描述在这里.相关代码是:
foreign import ccall unsafe "conio.h getch" c_getch :: IO CInt
Run Code Online (Sandbox Code Playgroud)
当我在ghci中运行它或使用ghc编译它时,这很好.我也想尝试制作一个cabal包,所以从这个问题延伸,我在我的cabal文件中包含以下内容:
...
executable noughts
Includes: conio.h
Extra-libraries conio
...
Run Code Online (Sandbox Code Playgroud)
但是当我跑步时cabal configure,它告诉我:
cabal: Missing dependency on a foreign library:
* Missing C library: conio
Run Code Online (Sandbox Code Playgroud)
这是有道理的,因为在我的haskell平台目录下...\Haskell Platform\2012.4.0.0\mingw,目录下有一个conio.h文件include,但没有其他conio文件提供目标代码.
我是以正确的方式做到这一点,如果是这样,我怎样才能找出要包含在我的cabal文件中的库?
在Windows上,我有以下代码来查找输入而不中断循环:
#include <conio.h>
#include <Windows.h>
#include <iostream>
int main()
{
while (true)
{
if (_kbhit())
{
if (_getch() == 'g')
{
std::cout << "You pressed G" << std::endl;
}
}
Sleep(500);
std::cout << "Running" << std::endl;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,看到没有conio.h,在Linux上实现这一点的最简单方法是什么?
在运行简单的c程序时,我会收到一个
Unresolved inclusion: <conio.h>
Run Code Online (Sandbox Code Playgroud)
我错过了什么?我正在使用eclipse fedora 13.请帮我解决这个问题.如果我遗漏任何文件或没有安装任何东西,请告诉我.我也是Fedora的新手.请指导我正确的步骤.
提前致谢.
我在Windows上写了这个简单的程序.由于Windows有conio,它工作得很好.
#include <stdio.h>
#include <conio.h>
int main()
{
char input;
for(;;)
{
if(kbhit())
{
input = getch();
printf("%c", input);
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想将它移植到Linux,而curses/ncurses似乎是正确的方法.如何使用这些库代替conio来实现同样的目标?
#include <conio.h>
int main (void)
{
for (;;)
{
unsigned char ch = getch();
printf ("0x%02X\n", ch);
}
}
Run Code Online (Sandbox Code Playgroud)
我想获得扫描码.
以下是维基百科的描述:
Reads a character directly from the console without buffer, and without echo.
Run Code Online (Sandbox Code Playgroud)
当我按下时Del,它显示0xE0 0x53.
当我按下Ctrl+时PgUp,它显示0xE0 0x86.
虽然有些与表格相同,但它显示的大部分值都与之不同.
那么,getch()真的能获得扫描码吗?
这是扫描码表(第2组,最常用)
for (;;)
{
cout << "You are playing for:" << playtime << "seconds." << endl;
cout << "You have " << bytes << " bytes." << endl;
cout << "You are compiling " << bps << " bytes per second." << endl;
cout << "Press a to buy assembler monkey (produces 1 byte per second)/(cost 10 bytes)" << endl;
switch(getch())
{
case 'a': bytes = bytes - 10; bps++; break;
}
bytes = bytes + bps;
playtime++;
Sleep(1000);
system("cls");
} …Run Code Online (Sandbox Code Playgroud) 我经常看到人们使用conio.hC 和 C++ 中的头文件,尽管conio.h与标准库函数相比,我看不到使用内部函数的任何主要好处。conio.h此外,还存在依赖于 Windows/MS-DOS 环境且不属于 C 标准的缺点。
conio.h什么?conio.h提供什么,标准C库的功能不能提供什么?conio图书馆?我在ubuntu中使用gcc .so,我在终端编译并执行.但是在在线编程竞赛中,他们需要如图所示的输出.

为此,如果我使用TURBOC,我可以使用conto.h使用gotoxy()来获得输出的螺旋格式.但是在Ubuntu中,我怎么能实现这个目标呢?
我通常使用 VS 但第一次尝试 cygwin。我正在使用 Windows 7,但是在使用 gcc 编译 hello world 程序时,它说“致命错误:conio.h:没有这样的文件或目录”。
我使用的是 Windows 7,我的系统中似乎缺少 conio.h。有人可以告诉我如何解决这个问题。
谢谢!!
他们询问如何捕获诸如F11或insand之类的密钥getchr不会为这些密钥返回任何内容,并且我找不到任何可以接受来自输入事件的原始输入的工作.
我现在正在尝试使用C++程序中的ncurses/curses来捕获这些键.
我的测试程序很简单,基本上是:
#include <stdlib.h>
#include <stdio.h>
#include <curses.h>
int main() {
int car;
while(c != '\b') {
c = getch();
printf("%i", c);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我当然使用它与另一个getch()函数相同,但它返回-1无限次..我在Arch linux中使用最近的内核,在标准终端中(也在测试中xterm)
是否需要打开某个开关才能在库中使用此getch()?
我想使用递归查找数组的最大和最小元素。这是我写的程序,我已经完成了逻辑,它似乎是完美的。但是当我编译程序时,程序在输入后卡住了。
这是我的程序:
#include<stdio.h>
#include<conio.h>
int max(int a[], int n);
int min(int a[], int n);
void main(){
int a[100],n,i,maxi,mini;
clrscr();
printf("Enter the number of elements ");
scanf("%d",&n);
printf("Enter the elements of array ");
for(i=0;i<n;i++)
{
scanf("%d \n",&a[i]);
}
maxi = max(a,n);
mini = min(a,n);
printf("\nMaximum element : %d",maxi);
printf("\nMinimum element : %d",mini);
getch();
}
int max(int a[],int n){
int maxo=0,i=0;
if(i<n){
if(maxo < a[i]){
maxo=a[i];
}
i++;
max(a,n);
}
return maxo;
}
int min(int a[],int n){
int mino=999,i=0;
if(i<n){
if(mino > …Run Code Online (Sandbox Code Playgroud) 我正在制作一个小C程序,要求输入密钥并在switch语句中执行一些代码.
#include <stdio.h>
#include <conio.h>
int main(int argc, char const *argv[]){
/* code */
printf("Hello, press a, b or c to continue");
char key = getch();
switch (key){
case 'a':
clrscr();
//some code
break;
case 'b':
//many lines of code
break;
case 'c':
clrscr();
//many lines of code
break;
default:
printf("Ok saliendo\n");
break;
}
printf("bye");
}
Run Code Online (Sandbox Code Playgroud)
getch()工作正常,但clrscr()不是,即使我包括在内<conio.h>.
为什么?