Originally Posted by
andyouf
My professor wants getNumber to be a function that takes in an address parameter so that the integer entered in keyboard is picked up. I have that down
I do not think so.
Version 1 "getNumber to be a function "
Code:
/* Function definition */
/* getNumber is a function which takes no parameters, returns nothing, and does nothing. */
void getNumber(void)
{
}
int main(void)
{
getNumber(); /* call to getNumber */
return 0;
}
Version 2 "getNumber to be a function that takes in an address parameter "
Code:
/* Function definition */
/* getNumber is a function which takes an address of a number, returns nothing, and does nothing.
WARNING: Will not set the value of *number_ptr. */
void getNumber(int * number_ptr)
{
}
int main(void)
{
int number;
getNumber(&number); /* call to getNumber */
return 0;
}
Version 3 "getNumber to be a function that takes in an address parameter so that the integer entered in keyboard is picked up"
Code:
#include <stdio.h>
/* Function definition */
/* getNumber is a function which takes an address of a number, returns nothing, and prompts the user for a number and returns it to the address passed. Uses code from the original poster. */
void getNumber(int * number_ptr)
{
printf("Enter integer:");
scanf("%d", number_ptr); /* read a single integer value input */
}
int main(void)
{
int number;
getNumber(&number); /* call to getNumber */
return 0;
}
Originally Posted by
andyouf
but I don't see how to make this a separate function outside of main?
I hope that is answered by the above.