#include #include "prog3.h" /* Function tryToGet2Nums (BROKEN!): * Prompts the user to input two numbers (integers). * Retrieves the numbers from the user and attempts to return them. */ void tryToGet2Nums(int num1, int num2) { /* Prompt the user for first number... */ printf("\tIn tryToGet2Nums: Please enter a number: "); scanf("%d", &num1); /* NOTE: C passes by VALUE, so we need to pass the ADDRESS * of num1 for the function to change its value. * In scanf, %d indicates [the address of] a decimal integer. */ /* Prompt the user for second number... */ printf("\tIn tryToGet2Nums: Please enter a second number: "); scanf("%d", &num2); /* Print num1 and num2. */ printf("\n\tIn tryToGet2Nums: num1 = %d; num2 = %d.\n", num1, num2); } /* Function get2Nums: * Prompts the user to input two numbers (integers). * Retrieves the numbers from the user, putting them at the addresses * POINTED TO by the parameters. */ void get2Nums(int * num1, int * num2) { /* Prompt the user for first number... */ printf("\tIn get2Nums: Please enter a number: "); scanf("%d", num1); /* NOTE: num1 is a POINTER TO an int, so is the appropriate * type for passing to scanf. */ /* Prompt the user for second number... */ printf("\tIn get2Nums: Please enter a second number: "); scanf("%d", num2); /* Print num1 and num2. */ printf("\n\tIn get2Nums: num1 = %d; num2 = %d.\n", *num1, *num2); /* NOTE: In printf, %d indicates an int, not a pointer to an * int. "num1" is a pointer to an int; "*num1" is the int * it points to. */ }