Question: help me with code and compile, below is code guidelines, dont change guidlines: #include #include #include #include #define MAXLINE 1 0 0 / / function

help me with code and compile, below is code guidelines, dont change guidlines:
#include
#include
#include
#include
#define MAXLINE 100
// function prototypes
void encode(unsigned char first_letter, unsigned char second_letter,
unsigned char third_letter);
void decode(unsigned int codeword);
int main()
{
char line[MAXLINE];
char command[MAXLINE];
char inputcs[MAXLINE];
int items;
int i, invalid;
unsigned int codeword;
printf("
PP2: encoding and decoding (29,24) Hamming code.
");
printf("Commands:
\tenc 3-letters
\tdec 8-hex-digits
\tquit
");
// each call to fgets, collects one line of input and stores in line
while (fgets(line, MAXLINE, stdin)!= NULL){
items = sscanf(line,"%s%s", command, inputcs);
if (items ==1 && strcmp(command, "quit")==0){
break;
} else if (items ==2 && strcmp(command, "enc")==0){
// encoding
if (strlen(inputcs)!=3||!isprint(inputcs[0])||
!isprint(inputcs[1])||!isprint(inputcs[2])){
printf("Invalid input to encoder: %s
", inputcs);
} else {
encode(inputcs[0], inputcs[1], inputcs[2]);
}
} else if (items ==2 && strcmp(command, "dec")==0){
// decoding: convert hex digits to integer
items = sscanf(inputcs,"%x", &codeword);
if (items !=1|| strlen(inputcs)>8){
printf("Invalid input to decoder: %s
", inputcs);
} else {
for (i=0, invalid=0; i strlen(inputcs) && !invalid; i++){
if (!isxdigit(inputcs[i]))
invalid =1;
}
// if 8 digits, leading digit must be 1 or 0
if (invalid){
printf("Invalid decoder digits: %s
", inputcs);
} else if (strlen(inputcs)==8 && inputcs[0]!='1'
&& inputcs[0]!='0'){
printf("Invalid decoder leading digit: %s
", inputcs);
} else {
decode(codeword);
}
}
} else {
printf("# :%s", line);
}
}
printf("Goodbye
");
return 0;
}
* encode: calculates parity bits and prints codeword
*
* input: three ASCII characters
* assumptions: input is valid
*
* Example: if input letters are is 'C','U', and 't'
* the final print must be:
*---01110100010100101010010011100
* Codeword: 0x0E8A549C
*/
void encode(unsigned char first_letter, unsigned char second_letter,
unsigned char third_letter)
{
// you must construct the codeword
unsigned int codeword =0;
int i =-1; // dummy variable
printf("%9s%9c%9c%9c
", "Encoding:", third_letter, second_letter,
first_letter);
printf("0x 00%9x%9x%9x
", third_letter, second_letter, first_letter);
//
// ADD your code here
//
// print the information word in binary form with spaces
// print the parity bits, one bit per line. Do not change
// the format, but you must change the dummy variable i
// to match your design
printf("P1 : %d
", i);
printf("P2 : %d
", i);
printf("P4 : %d
", i);
printf("P8 : %d
", i);
printf("P16: %d
", i);
// print the codeword bits in binary form with spaces
// print the codeword in hex format
printf(" Codeword: 0x%.8X
", codeword);
printf("
");
}
/* decode: checks parity bits and prints information characters
*
* input: A 29-bit codeword
* assumptions: the codeword has either no or only one error.
*
* the information characters may not be printable
*
* FYI: when a codeword has more than one error the decoding algorithm
* may generate incorrect information bits. In a practical system
* inforamtion is grouped into multiple codewords and a final CRC
* code verifies if all codewords are correct. We will not
* implement all of the details of the system in this project.
** Example: if the codeword is 0x0E8A549C
* the final print must be:
* No error
*--------011101000101010101000011
* Information Word: 0x745543(CUt)
*
* Example with one error in codeword bit 21: 0x0E9A549C
* Notice the 8 in the previous example has been changed to a 9
* the final print must be:
* Corrected bit: 21
*--------011101000101010101000011
* Information Word: 0x745543(CUt)
*/
void decode(unsigned int codeword)
{
// you must determine these values:
unsigned int info_word =0;
unsigned char first_letter =0x42;
unsigned char second_letter =0x61;
unsigned char third_letter =0x64;
int bit_error_location =21;
// dummy variable
int i =-1;
printf("Decoding: 0x%.8X
", codeword);
//
// ADD your code here to fix a bit error if one exists
// and determine the three characters
printf("E1 : %d
", i);
printf("E2 : %d
", i);
printf("E4 : %d
", i);
printf("E8 : %d
", i);
printf("E16: %d
", i);
if (bit_error_location ==0)
printf(" No error
");
else if (bit_error_location >0 && bit_error_location =29){
printf(" Corrected bit: %d
", bit_error_location);
} else
printf(" Decoding failure: %d
", bit_error_location);
if ((first_letter & 0x80)==0 && isprint(first_letter))
printf("(%c", first_letter);
else
printf("");
if ((second_letter & 0x80)==0 && isprint(second_letter))
printf("%c", second_letter);
else
printf("");
if ((third_letter & 0x80)==0 && isprint(third_letter))
printf("%c)
", third_letter);
else
printf(")
");
printf("");
}
help me with code and compile, below is code

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 Programming Questions!