Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

once run an example would look like [user]$ ./decode < example.enc Hello World!

ID: 3596894 • Letter: O

Question

once run an example would look like

[user]$ ./decode < example.enc

Hello World!

Image Decoder Not all encodings compress data. Sometimes, there is a need to introduce re- dundancy, or to re encode a file so that it can be transmitted using a specific protocol. In this case, the encoding is an entirely arbitrary. Your program will read single characters until the character z is found. The following set of characters are accepted: a, A, b, B, c,z. A variable, total, is also defined, and initiallv set to zero. Each character adds to the total according to the following table: If a 'c' is seen, then the total is printed as a character (%c), not an integer (%d). The total variable is then reset to zero If a 'z' is seen, then there is no more data: the program should exit Open the file decode.c. All the variables you require are defined. Complete the program using either a nested if statement or a switch statement.

Explanation / Answer

#include<stdio.h>

int main()

{

char c='a';

char total=0;;

while(c!='z')

{

scanf("%c",&c);

if(c=='a')

total+=1;

else if(c=='A')

total+=2;

else if(c=='b')

total+=4;

else if(c=='B')

total+=8;

else if(c=='c')

{

printf("%c ",total);

total=0;

}

}

return 0;

}