Analog of getch() when using gcc
The bottom line: I used to use Visual Studio 2015, in it, I connect the conio library. h I used the _getch () function. Now I decided to switch to a product from Jetbrains-Clion. Everything would be fine, but the gcc compiler and the conio.h library just don't see it there. Accordingly, I can't use _getch() in any way.
What I actually need it for. Here are the functions where I use them:
void pressEnterForContinue()
{
rewind(stdin);
printf(" Нажмите ENTER для продолжения работы программы. \n\n");
while (getchar() != "\r");
}
char getCharCustom()
{
char c;
c = _getch();
if (c == '\r')
c = '\n';
if (c != '\b' && c != NULL)
printf("%c", c);
return c;
}
That is, I want to get a keyboard symbol by pressing a key. getchar() returns only the character code. Sticking to pure C without using C++
1
2 answers
Try using the ncurses library.
4
Author: Vanyamba Electronics, 2016-05-20 18:42:58
As a function of _getch()
, you can use read()
int size;
char c;
for(;;){
size = read(fileno(stdin),&c,1);
if(c == '\n'){
break;
}
if (c != '\b' && c != NULL)
printf("%c", c);
}
1
Author: Yaroslav, 2016-05-21 04:01:50