i would like to know if there are are ways to make the terminal not echo what we write using only the standard C
library ?

- 146
- 10
-
3It is compiler dependent because terminal control will be OS dependent. Linux has `termios.h` (POSIX, not standard C), windows has something different. What OS? For Linux/Unix, you can see [Hide password input on terminal](https://stackoverflow.com/questions/6856635/hide-password-input-on-terminal/32421674?r=SearchResults&s=1|47.6635#32421674) – David C. Rankin Oct 10 '19 at 01:11
-
It would be for Linux and MacOS. I have seen other options using non standard libraries. If there are no ways to do it directly using one or two functions then i will have to do it using non standard way. Btw thanks for your answer. – localhost Oct 10 '19 at 01:40
-
Which options did you find? Without knowing what you tried we can't help you. – the busybee Oct 10 '19 at 06:21
-
it's not that i have a problem with code. I have already tried ncurse and other library similar to it which worked fine, but i waned to know if there was some easy `API` in the standard library so i won't have to use a third party library for only one thing. – localhost Oct 10 '19 at 06:59
1 Answers
If by "only the standard C library" you mean to restrict to those functions defined by the C language standard, then no. The language standard acknowledges the existence of a variety of I/O devices with differing characteristics, but it makes no provisions for managing any of them.
If instead you mean simply that you don't want to install or link additional libraries to your program then it's platform specific, but often yes, there are terminal-management functions provided that way. In particular, POSIX defines a terminal-control interface whose functions and data structures are sometimes known as "termios", after the POSIX-standard termios.h header file where they are declared. I'm not so sure I would characterize it as an "easy API", but it should allow you to turn off keyboard input being echoed to the terminal display via two functions calls (or just one, depending on how you count). You would want to look specifically at the tcgetattr() and tcsetattr() functions. You should be able to use that method on Linux, and probably also on macOS.

- 160,171
- 8
- 81
- 157