conio

Printing in windows console on x,y position

时光怂恿深爱的人放手 提交于 2019-12-11 09:58:23
问题 I want to print, in a certain (X,Y) position, on a standard console in windows. I tried to use conio.h, but is deprecated/non-existing. There was the gotoxy(x,y) method that seems to be what I want. I've tried these ways, but it just prints extra characters: printf("%c[%d;%df",0x1B,y,x); printf("\x1B%c[%d;%df",0x1B,y,x); printf("\x1B[%d;%dH", 0x1B, y, x); Thanks in advance. 回答1: The Windows API call to position the cursor in a console is SetConsoleCursorPosition. As someone commented, "curses

Strange behavior with function parameters and getch()

时光毁灭记忆、已成空白 提交于 2019-12-11 04:28:50
问题 I am running in to some strange behavior with calling functions with parameters that contain getch(). Take the following code for example: _Bool IsKeyDown(char c) { if(!kbhit()) return 0; char ch1 = getch(); printf("%c\n", c); return 0; } /* * */ int main(int argc, char** argv) { while(1) { IsKeyDown('a'); IsKeyDown('b'); Sleep(100); } return (EXIT_SUCCESS); } When a key is pressed with this code, no matter what, it will always print 'a', which is the parameter of the first function. The

getch returns -1?

邮差的信 提交于 2019-12-06 07:46:37
问题 They asked how to capture keys such as F11 or insand getchr does not return anything for those keys, and there is nothing I can find working that accepts raw input from input events.. I am now trying ncurses/curses in a C++ program to capture these keys. My program to test is simple, it is basically: #include <stdlib.h> #include <stdio.h> #include <curses.h> int main() { int car; while(c != '\b') { c = getch(); printf("%i", c); } return 0; } I use it of course the same as another getch()

How do I port this program from conio to curses?

戏子无情 提交于 2019-12-04 05:33:07
I wrote this simple program on Windows. Since Windows has conio, it worked just fine. #include <stdio.h> #include <conio.h> int main() { char input; for(;;) { if(kbhit()) { input = getch(); printf("%c", input); } } } Now I want to port it to Linux, and curses/ncurses seems like the right way to do it. How would I accomplish the same using those libraries in place of conio? #include <stdio.h> #include <ncurses.h> int main(int argc, char *argv) { char input; initscr(); // entering ncurses mode raw(); // CTRL-C and others do not generate signals noecho(); // pressed symbols wont be printed to

conio.h is missing from Windows

﹥>﹥吖頭↗ 提交于 2019-12-01 21:08:54
I usually use VS but trying cygwin for the first time. I am using windows 7 but on compiling hello world program using gcc, it says "fatal error: conio.h: no such file or directory". I am using Windows 7 and it seems conio.h is missing from my system. Can someone please tell me how to resolve this issue. Thanks!! In Cygwin there doesn't exist any such header file called conio.h ! Also, you don't need it either because it automatically holds screen for you without using getch() and for clrscr() you do have system("clear") in Cygwin! conio not being part of the standard library, you cannot

clrscr() not working, getch() working. Why?

白昼怎懂夜的黑 提交于 2019-11-28 11:00:10
问题 I'm making a small C program that asks for a key and executes some code in a switch statement. #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"); } getch() is working properly, but clrscr() is not

How could I achieve gotoxy() in gcc

孤街浪徒 提交于 2019-11-28 10:23:34
I am using gcc in ubuntu .so, I compile and execute in terminal . But In a online programming contest, they require the output as shown in diagram. For that, if I use TURBOC I can get it using conio.h using gotoxy() to get spiral format of output. But in Ubuntu , How could I achieve this? Use the ncurses library. Here's an example, adapted from http://www.paulgriffiths.net/program/c/srcs/curhellosrc.html #include <stdlib.h> #include <stdio.h> #include <curses.h> int main(void) { WINDOW * mainwin; /* Initialize ncurses */ if ( (mainwin = initscr()) == NULL ) { fprintf(stderr, "Error

How to run program whilst listening for user input in C?

纵饮孤独 提交于 2019-11-28 00:32:35
I'm trying to make a game that continues running until a key is pressed and then it should take that key in and do something with it then continue running as per normal. How do I do this? I'm on MAC so even though I've come across a windows library called conio.h which can handle this using kbhit() and getch(), I can't get it working for me... // // main.c // conioTesting // // #include <stdio.h> #include "myconio_mac.h" int main(int argc, const char * argv[]) { int counter = 0; while (counter < 2) { if (kbhit()) { char key = getch(); printf("\n Key is %c \n", key); printf("Keyboard hit

How could I achieve gotoxy() in gcc

淺唱寂寞╮ 提交于 2019-11-27 02:56:03
问题 I am using gcc in ubuntu .so, I compile and execute in terminal . But In a online programming contest, they require the output as shown in diagram. For that, if I use TURBOC I can get it using conio.h using gotoxy() to get spiral format of output. But in Ubuntu , How could I achieve this? 回答1: Use the ncurses library. Here's an example, adapted from http://www.paulgriffiths.net/program/c/srcs/curhellosrc.html #include <stdlib.h> #include <stdio.h> #include <curses.h> int main(void) { WINDOW *

How to run program whilst listening for user input in C?

 ̄綄美尐妖づ 提交于 2019-11-26 17:07:41
问题 I'm trying to make a game that continues running until a key is pressed and then it should take that key in and do something with it then continue running as per normal. How do I do this? I'm on MAC so even though I've come across a windows library called conio.h which can handle this using kbhit() and getch(), I can't get it working for me... // // main.c // conioTesting // // #include <stdio.h> #include "myconio_mac.h" int main(int argc, const char * argv[]) { int counter = 0; while