Question: Trying to make a program that where the user inputs any characters and numbers from the keyboard, when the sequence 01111110 is typed in the

Trying to make a program that where the user inputs any characters and numbers from the keyboard, when the sequence 01111110 is typed in the program is supposed to display a HDLC flag. The program works so far, but when some of the keys are entered the program displays key entries twice. If I push k for example the terminal will show kk. I have tried this on different platforms and getting the same results. Below is what im working on so far.

#include #include #include #include #include

int main() { char ch; // char char HDLCflag[] = "01111110"; // key char chacker[8]; // input key container char data[256]; // data container int i = 0, c = 0, d = 0; memset(data, 0, 256); // printf("Press Any Key to Continue and it will be read automaticly "); printf("for this expirment to work only enter 0's and 1's and 'e' exit Thank You "); system ("/bin/stty raw"); // this sets the key inputs to raw while (1) { ch = getchar(); printf("%c",ch);// prints what you are typing // receving char when in container if (c == 1) { data[d] = ch; d++; } //move over key checker string char for (i = 7; i >= 0; i--) { if (i == 0) { chacker[i] = ch; break; } else { chacker[i] = chacker[i-1]; } } //checks for flags if (chacker[0] == HDLCflag[0] && chacker[1] == HDLCflag[1] && chacker[2] == HDLCflag[2] && chacker[3] == HDLCflag[3] && chacker[4] == HDLCflag[4] && chacker[5] == HDLCflag[5] && chacker[6] == HDLCflag[6] && chacker[7] == HDLCflag[7]) { if (c == 1) { c--; system ("/bin/stty cooked"); // this sets the key inputs to processed printf(" (End flag has been detected) HDLC FLAG "); data[d-8] = '\0'; printf(" data : %s ",data); printf(" (continuing to receive) "); system ("/bin/stty raw"); // this sets the key inputs to processed }else { system ("/bin/stty cooked"); // this sets the key inputs to processed printf(" (continuing to receive) HDLC FLAG "); system ("/bin/stty raw"); // this sets the key inputs to processed c++; } } // exits on 'e' only when not receving if (ch == 'e' && c == 0) { system ("/bin/stty cooked"); // this sets the key inputs to processed printf(" "); system ("/bin/stty raw"); // this sets the key inputs to processed break; } } system ("/bin/stty cooked"); // this sets the key inputs to processed return 0; } // end main

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!