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

Please use Do While and Switch Case to solve this problem. Please fill in the co

ID: 3700030 • Letter: P

Question

Please use Do While and Switch Case to solve this problem. Please fill in the code where it says write your code.

In the following c code given below, there is a function called process which takes one argument, a single integer, and returns an integer value.

There are also a number of symbolic constants defined at the beginning of the file.

The process function should include a switch case using the argument as it’s condition value.

For every symbolic constant at the beginning of the tile, there should be a separate case for that value. They should do the following:

·         For ERROR_404, the switch should print “Not Found.” on its own line.

·         For ERROR_403, the switch should print “Forbidden.” on its own line.

·         For ERROR_400, the switch should print “Bad Request.” on its own line.

Also, include a case for EOF.For EOF, the switch should print “End of Stream” and then return 0 or FALSE.

In the default case, print “Valid input found: ” and then the argument as an ASCII character followed by a newline character.

If the argument wasn’t EOF, then the process function should return 1 or TRUE.

In the main file, write a do while loop to read one character of input from standard input at a time and pass it to the process function as an integer. Since we’re letting the process function handle EOF, don’t cast the input down to an integer just yet.

Use the process function’s return value to decide if the loop should continue as the do while’s condition.

This program should only contain ONE (1) instance of the getchar function and NO OTHER INPUT FUNCTIONS!
?
?Code


#include <stdio.h>

#define ERROR_404 'a'
#define ERROR_403 'b'
#define ERROR_400 'c'

enum bool { FALSE, TRUE };

int process(int code) {
    /* write your code here. */
}

void main() {
    /* write your code here */
}

Example Input : abcbacbHello, Student!
Output :

Not Found.

Forbidden.

Bad Request.

Forbidden.

Not Found.
Bad Request.
Forbidden.
Valid input found: H
Valid input found: e
Valid input found: l
Valid input found: l
Valid input found: o
Valid input found: ,
Valid input found:
Valid input found: S
Valid input found: t
Valid input found: u
Valid input found: d
Valid input found: e
Valid input found: n
Valid input found: t
Valid input found: !


Explanation / Answer

Implemented code as per the requirement. Please comment if you need any modification.

Code:

====

#include <stdio.h>

#define ERROR_404 'a'
#define ERROR_403 'b'
#define ERROR_400 'c'

enum bool { FALSE, TRUE };

int process(int code) {
  
switch(code){
case ERROR_404:
printf("Not Found. ");
break;
case ERROR_403:
printf("Forbidden. ");
break;
case ERROR_400:
printf("Bad Request. ");
break;
default :
printf("Valid input found: %c ",code);
break;
}
  
}

void main() {
char ch = 'a';
while(1){
ch = getchar();
if(ch==EOF){
printf("End of stream ");
break;
}
process(ch);
}
}