Added files from the first CIS 452 lab.
This commit is contained in:
commit
874b4f36bd
|
@ -0,0 +1,42 @@
|
||||||
|
#include <termios.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define TERMINAL_FD 0
|
||||||
|
#define MAX_CHARS 50
|
||||||
|
#define LOWERCASE_W 119
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Declaring the variables we'll be using.
|
||||||
|
struct termios old, new;
|
||||||
|
char *input;
|
||||||
|
|
||||||
|
// Grabbing terminal settings.
|
||||||
|
tcgetattr(TERMINAL_FD, &old);
|
||||||
|
new = old;
|
||||||
|
|
||||||
|
// Getting memory from the heap for the input string.
|
||||||
|
input = malloc(sizeof(char) * MAX_CHARS);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Setting erase key to w. I figured out how to do
|
||||||
|
* this using the man page given here:
|
||||||
|
* http://man7.org/linux/man-pages/man3/termios.3.html/
|
||||||
|
*/
|
||||||
|
new.c_cc[VERASE] = LOWERCASE_W;
|
||||||
|
tcsetattr(TERMINAL_FD, TCSANOW, &new);
|
||||||
|
|
||||||
|
// Pressing the w key erases input!
|
||||||
|
printf("Press the w key to erase: ");
|
||||||
|
fgets(input, MAX_CHARS, stdin);
|
||||||
|
printf("\nYou entered: %s", input);
|
||||||
|
|
||||||
|
// Reverting settings.
|
||||||
|
tcsetattr(TERMINAL_FD, TCSANOW, &old);
|
||||||
|
|
||||||
|
// Freeing memory allocated.
|
||||||
|
free(input);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
#include <termios.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define TERMINAL_FD 0
|
||||||
|
#define MAX_CHARS 50
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Declaring the variables we'll be using.
|
||||||
|
struct termios old, new;
|
||||||
|
char *input;
|
||||||
|
|
||||||
|
// Grabbing terminal settings.
|
||||||
|
tcgetattr(TERMINAL_FD, &old);
|
||||||
|
new = old;
|
||||||
|
|
||||||
|
// Getting memory from the heap for the input string.
|
||||||
|
input = malloc(sizeof(char) * MAX_CHARS);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Turning off echo. I figured out how to do
|
||||||
|
* this using the man page given here:
|
||||||
|
* http://man7.org/linux/man-pages/man3/termios.3.html/
|
||||||
|
*/
|
||||||
|
printf("Disabling echo.\n");
|
||||||
|
new.c_lflag = new.c_lflag & ~ECHO;
|
||||||
|
tcsetattr(TERMINAL_FD, TCSANOW, &new);
|
||||||
|
|
||||||
|
// Entering phrase without echo!
|
||||||
|
printf("Enter secret word/phrase: ");
|
||||||
|
fgets(input, MAX_CHARS, stdin);
|
||||||
|
printf("\nYou entered: %s\n", input);
|
||||||
|
|
||||||
|
// Reverting settings.
|
||||||
|
printf("Default behavior restored.\n");
|
||||||
|
tcsetattr(TERMINAL_FD, TCSANOW, &old);
|
||||||
|
|
||||||
|
// Entering phrase with echo.
|
||||||
|
printf("Enter visible word/phrase: ");
|
||||||
|
fgets(input, MAX_CHARS, stdin);
|
||||||
|
printf("You entered: %s", input);
|
||||||
|
|
||||||
|
// Freeing memory allocated.
|
||||||
|
free(input);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue