/* * programming_functions_cont.c * * Created on: Oct 10, 2023 * Author: johnsontimoj */ ///////////////////////////////// // // Program to practice some functions - continued // // inputs - from user // outputs - some prints // /////////////////////////////////// #include #include /////////////////// // function declarations (prototypes) //////////////////// char capitalize(char val); int read_int(void); char read_char(void); float read_float(void); int main(void){ // we now know this is just a function setbuf(stdout, NULL); char a; // call capitalize function // printf("Please enter a character: "); // scanf(" %c", &a); // don't forget the space before the %c a = read_char(); a = capitalize(a); // remember, the value of a is passed into the function, not the variable printf("a is: %c\n", a); return 0; // we know this is required by the function definition }// end main /////////////////////////// // function definitions ////////////////////////// ////////////////////////////////////// // capitalize // // function to return the capital of a letter // ignores non letter inputs // // input: letter as a char // output: capital letter as a char //////////////////////////////////////// char capitalize(char val){ char tmp_val; if((val >= 'a') && (val <= 'z')) tmp_val = val - 0x20; else tmp_val = val; return tmp_val; }// end capitalize ///////////////////////////// // Helper functions //////////////////////////// ////////////////////////////////////// // read_int // // function to ask for and read in an int // // input: none // output: returns the int //////////////////////////////////////// int read_int(void){ int val; printf("please enter an int: "); scanf("%i", &val); return val; }// end read_int ////////////////////////////////////// // read_float // // function to ask for and read in a float // // input: none // output: returns the float //////////////////////////////////////// float read_float(void){ float val; printf("please enter a float: "); scanf("%f", &val); return val; }// end read_float ////////////////////////////////////// // read_char // // function to ask for and read in a char // // input: none // output: returns the char //////////////////////////////////////// char read_char(void){ char val; printf("please enter a char: "); scanf(" %c", &val); return val; }// end read_char