C programming
Practice how to set the terminal setting.
Instruction:
Write a C program that will check the current setting of “echo”.It it is on, display the message and turn it off. If it is off,display the message and turn it on,
Thing to submit:
1. A c program with header and comments documentation,.
2. A screen shots showing the successful execution oftesting.
Solution
C program :-
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
main (){
struct termios term_inst, save;
int ret_val;
ret_val =tcgetattr(0,&term_inst);
if(ret_val == -1 ){
perror(“tcgetattr”);
exit(1);
}
if(term_inst.c_lflag &ECHO){
printf(“ECHO is ON, will turn it OFF! n”);
term_inst.c_Lflag &= ~ECHO; /* turn off ECHO*/
if(tcgetattr(0,&term_inst) != 0){
perror(“tcgetattr”);
exit(1);