/* * debug_demo.c * * Created on: Jan 24, 2021 * Author: johnsontimoj */ #include void splash(void); void read_input(int* intval_ptr, float* floatval_ptr, char* charval_ptr); int ifelsefn(int val); int casefn(int* intval_ptr, float* floatval_ptr); int main(void){ setbuf(stdout, NULL); int x; int y; char aa; char bb; float one; float two; x = 3; y = 4; aa = 'f'; bb = 'g'; one = 1.003; two = 2.222; printf("%i %i\n", x, y); // splash screen splash(); // input values read_input(&x, &one, &aa); // ifelse function y = ifelsefn(x); // case function y = casefn(&x, &two); // port manipulation printf("%i %i\n", x, y); printf("%f %f\n", one, two); printf("%c %c\n", aa, bb); return 0; }// end main //////////////////////// // splash // // code to print splash screen // // input: none // output - prints message to screen // retrun - viod ///////////////////////// void splash(void){ printf("\nProgram to demonstrate the debugger\n\n"); return; }// end splash //////////////////////// // read_input // // read in an int, a float, and a char // // inputs - none // output - int/float/char via pointers // return - void //////////////////////////// void read_input(int* intval_ptr, float* floatval_ptr, char* charval_ptr){ printf("Please enter an int, a float, and a character: \n"); scanf("%i %f %c", intval_ptr, floatval_ptr, charval_ptr); return; }// end read_input ////////////////////////////// // ifelsefn // // selects an output for a given input // // inputs - int to select on // output - none // return - random value based on input //////////////////////// int ifelsefn(int val){ int result; if(val == 0) result = 5; else if(val == 4) result = 9; else if(val >=5) result = 12; else result = -2; return result; }// end ifelsefn ////////////////////////////// // casefn // // selects an output for a given input // // input - pointer to value to change (and switch on), and float to multiply by // output - modifies the pointer value // return - original value input ////////////////////////////// int casefn(int* intval_ptr, float* floatval_ptr){ int inputval; int tmpval; inputval = *intval_ptr; tmpval = ifelsefn(*intval_ptr); switch(tmpval){ case 5: *intval_ptr = 6; *floatval_ptr *= 6; break; case 9: *intval_ptr = 10; *floatval_ptr *=10; break; default: *intval_ptr = 0; *floatval_ptr = 0; break; }// end switch return inputval; }// end casefn