Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continue running program until user type Ctrl + a

Tags:

c

linux

I'm practicing C programming for Linux for an exam. I don't know how to exit the program when user press Ctrl + a ( not Ctrl+c ) For example, looping something until user press Ctrl+a Could anyone tell me how to check Ctrl+a input?

Notes: I'm using 'gcc' and run output with './a.out'

Thanks in advance for everyone!

like image 739
Devyn Avatar asked Jan 23 '23 19:01

Devyn


1 Answers

Turbo C and other implementations of C for Windows had a function call getch() which would read single characters from the keyboard; those would have done what you want.

In POSIX environments, such as are implemented by gcc-compiled programs under Unix/Linux, that functionality isn't directly there.

There's a library called curses which allows C programs to do full-screen output processing, and there is also getch() functionality in curses. This may end up being the simplest answer to your problem. You'll need to read the documentation on curses and link the header files and library into your program.

like image 137
Carl Smotricz Avatar answered Jan 25 '23 22:01

Carl Smotricz