PDA

View Full Version : C programming (not C++), guru's help


newbie1
04-12-03, 03:25 PM
i have 3 questions:

1) in C (not C++) , how do you automate asterisks as the user types?

for example:

when the user types A, A will not show in output, instead an asterisk will show up, but the letter A is still in the buffer

just like a masked password

example?

2) In C (not C++) , the same as number one, but as a shadowed password?

3) In C (not C++) , for every 2 seconds i want a . (period) to show up until it reaches 10 dots, just like a progress bar or something, example?


This is only for my own knowledge, not for school or anything, i just always wanted to know the syntax for these 3 questions, i've been searching in search engines and i can't find any examples in C

cyberskye
04-13-03, 10:06 PM
Cut-n-pasted from courseware:

The easy way, is to use getpass(), which is probably found on almost all Unices. It takes a string to use as a prompt. It will read up to an EOF or newline and returns a pointer to a static area of memory holding the string typed in.

The harder way is to use tcgetattr() and tcsetattr(), both use a struct termios to manipulate the terminal. The following two routines should allow echoing, and non-echoing mode.

#include <stdlib.h>
#include <stdio.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;
}

Both routines used, are defined by the POSIX standard