131,043 views
43 votes
43 votes
Create a function, return type: char parameters: int *, int * Inside the function, ask for two integers. Set the user responses to the int * parameters. Prompt the user for a character. Get their response as a single character and return that from the function. In main Define three variables and call your function. Print values of your variables

User Kofriel
by
2.8k points

2 Answers

20 votes
20 votes

Final answer:

The student's question pertains to writing a function in C or a similar language that takes pointers as parameters, gets user input, and returns a character, which is then printed in the main function.

Step-by-step explanation:

The question is asking for the creation of a function in a programming context. The function is supposed to be of return type char, and it should take two int * parameters (pointers to integers). Inside the function, you will request the user to input two integers and a single character. The two integers provided by the user will be assigned to the provided pointer parameters, and the function will return the character input by the user.

In the main function, you are to define three variables: two int variables to catch the user inputs for the integers, and a char variable to catch the return value from the described function. After calling the function and obtaining the values, you will then print the values of these variables.

User Asraf
by
3.6k points
6 votes
6 votes

Answer and Explanation:

In C programming language:

char fun(int*a, int*b){

printf("enter two integers: ");

scanf("%d%d",a,b);

int e;

printf("please enter a character: ");

e=getchar();

return e;

}

int main(int argc, char *argv[]) {

int d;

int f;

int g;

fun();

printf("%d%d%d", d, f, g);

}

We have declared a function fun type char above and called it in main. Note how he use the getchar function in c which reads the next available character(after the user inputs with printf()) and returns it as an integer. We then return the variable e holding the integer value as char fun() return value.

User Egga Hartung
by
2.8k points