Question: Write a C program that carries out the function described in the instructions. Use the code template below to write the code. Do not change
Write a C program that carries out the function described in the instructions. Use the code template below to write the code. Do not change the template: labc
Your Name you must change to your name and id
PP
Purpose: A template for PP replace
Assumptions:
#: The menu driven input was provided and must be used exactly
as written. A user can enter commands:
enc CUt
dec EAC
quit
Encoding takes three printable ASCII letters
Decoding takes up to eight HEX digits. If exactly eight digits are
entered, the first digit must be or
Leading zeros can be dropped.
#: The string and character type libraries cannot be used except as
already provided. These libraries are for checking inputs in main
and in printing after decoding is complete. They cannot be used
for anyother purpose.
#: No arrays can be used excpet as already provided for collecting
keyboard input You must use bitwise operators for all encoding
and decoding. If you want to use an array as a lookup table you
must first propose your design and get it approved. Designs that
use tables to avoid bitwise operators will not be approved. There
are many good and simple designs that do not require tables.
# No changes to the code in main. Your code must be placed in
functions. Additional functions are encouraged.
Bugs:
See the ECE programming guide
If your formatting is not consistent you must fix it You can easily
reformat and automatically indent your code using the astyle
command. If it is not installed use the Ubuntu Software Center to
install astyle. Then in a terminal on the command line do
astyle stylekr labc
See "man astyle" for different styles. Replace kr with one of
ansi, java, gnu, linux, or google to see different options. Or set up
your own style.
To create a nicely formated PDF file for printing install the enscript
command. To create a PDF for "file.c in landscape with columns do:
enscript file.c GrE o pspdf file.pdf
#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
verify all digits are hex characters because
scanf does not reject invalid letters
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 first
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
