C Programming Practice Set Terminal Setting Instruction Write C Program Check Current Sett Q37110374

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);
  

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.