Input/Output function

M

maths_fan

Don't you know the function that can make input without writing
charecters on the output (under UNIX). I mean something like, when you
write Password on Unix, you write and the charecters are not seen, but
there are written in the buffer. Does anyone know any Unix library
(maybe a function that can do it). There is no in stdio.h as I found
out :(
 
J

Jonas Mellin

maths_fan said:
Don't you know the function that can make input without writing
charecters on the output (under UNIX). I mean something like, when you
write Password on Unix, you write and the charecters are not seen, but
there are written in the buffer. Does anyone know any Unix library
(maybe a function that can do it). There is no in stdio.h as I found
out :(
This is probably off-topic to this newsgroup, but here's my 2c:
Two possible solutions: Have a look at the 'curses' package or the
relevant ioctl calls for the tty (or pty) special file connecting to
your terminal/window. The former is simpler than the latter.
 
R

Richard Bos

Don't you know the function that can make input without writing
charecters on the output (under UNIX). I mean something like, when you
write Password on Unix, you write and the charecters are not seen, but
there are written in the buffer. Does anyone know any Unix library
(maybe a function that can do it). There is no in stdio.h as I found
out :(

<http://www.eskimo.com/~scs/C-faq/q19.1.html>.

HTH; HAND.

Richard
 
D

Dan Pop

In said:
Don't you know the function that can make input without writing
charecters on the output (under UNIX). I mean something like, when you
write Password on Unix, you write and the charecters are not seen, but
there are written in the buffer. Does anyone know any Unix library
(maybe a function that can do it). There is no in stdio.h as I found
out :(

getchar() works just fine, once you have disabled echoing, e.g. with
the stty command (that you can execute from your program with a
system() call).

Dan
 
E

Ed Morton

maths_fan said:
Don't you know the function that can make input without writing
charecters on the output (under UNIX). I mean something like, when you
write Password on Unix, you write and the charecters are not seen, but
there are written in the buffer. Does anyone know any Unix library
(maybe a function that can do it). There is no in stdio.h as I found
out :(

Someone posted this a while back:

#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <string.h>

static struct termios stored_settings;

void echo_off(void)
{
struct termios new_settings;
tcgetattr(0,&stored_settings);
new_settings = stored_settings;
new_settings.c_lflag &= (~ECHO);
tcsetattr(0,TCSANOW,&new_settings);
return;
}

void echo_on(void)
{
tcsetattr(0,TCSANOW,&stored_settings);
return;
}

int main()
{
int ch;
int ph = '*';
echo_off();
while((ch = getchar()) != EOF)
putchar(ph);
echo_on();

return 0;
}

Unfortunately I don't recall who to credit for it.

Regards,

Ed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,303
Messages
2,571,557
Members
48,359
Latest member
Raqib_121635
Top