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
function prototypes
void encodeunsigned char firstletter, unsigned char secondletter,
unsigned char thirdletter;
void decodeunsigned int codeword;
int main
char lineMAXLINE;
char commandMAXLINE;
char inputcsMAXLINE;
int items;
int i invalid;
unsigned int codeword;
printf
PP: encoding and decoding Hamming code.
;
printfCommands:
tenc letters
tdec hexdigits
tquit
;
each call to fgets, collects one line of input and stores in line
while fgetsline MAXLINE, stdin NULL
items sscanfliness command, inputcs;
if items && strcmpcommand "quit"
break;
else if items && strcmpcommand "enc"
encoding
if strleninputcsisprintinputcs
isprintinputcsisprintinputcs
printfInvalid input to encoder: s
inputcs;
else
encodeinputcs inputcs inputcs;
else if items && strcmpcommand "dec"
decoding: convert hex digits to integer
items sscanfinputcsx &codeword;
if items strleninputcs
printfInvalid input to decoder: s
inputcs;
else
for i invalid; i strleninputcs && invalid; i
if isxdigitinputcsi
invalid ;
if digits, leading digit must be or
if invalid
printfInvalid decoder digits: s
inputcs;
else if strleninputcs && inputcs
&& inputcs
printfInvalid decoder leading digit: s
inputcs;
else
decodecodeword;
else
printf# :s line;
printfGoodbye
;
return ;
encode: calculates parity bits and prints codeword
input: three ASCII characters
assumptions: input is valid
Example: if input letters are is CU and t
the final print must be:
Codeword: xEAC
void encodeunsigned char firstletter, unsigned char secondletter,
unsigned char thirdletter
you must construct the codeword
unsigned int codeword ;
int i ; dummy variable
printfsccc
"Encoding:", thirdletter, secondletter,
firstletter;
printfx xxx
thirdletter, secondletter, firstletter;
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
printfP : d
i;
printfP : d
i;
printfP : d
i;
printfP : d
i;
printfP: d
i;
print the codeword bits in binary form with spaces
print the codeword in hex format
printf Codeword: xX
codeword;
printf
;
decode: checks parity bits and prints information characters
input: A 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 xEAC
the final print must be:
No error
Information Word: xCUt
Example with one error in codeword bit : xEAC
Notice the in the previous example has been changed to a
the final print must be:
Corrected bit:
Information Word: xCUt
void decodeunsigned int codeword
you must determine these values:
unsigned int infoword ;
unsigned char firstletter x;
unsigned char secondletter x;
unsigned char thirdletter x;
int biterrorlocation ;
dummy variable
int i ;
printfDecoding: xX
codeword;
ADD your code here to fix a bit error if one exists
and determine the three characters
printfE : d
i;
printfE : d
i;
printfE : d
i;
printfE : d
i;
printfE: d
i;
if biterrorlocation
printf No error
;
else if biterrorlocation && biterrorlocation
printf Corrected bit: d
biterrorlocation;
else
printf Decoding failure: d
biterrorlocation;
if firstletter & x && isprintfirstletter
printfc firstletter;
else
printf;
if secondletter & x && isprintsecondletter
printfc secondletter;
else
printf;
if thirdletter & x && isprintthirdletter
printfc
thirdletter;
else
printf
;
printf;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
