Use function GetUserInfo to get a user's information. If user enters 20 and Holly, sample program output is:Holly is 20 years old. #include #include void GetUserInfo(int* userAge, char userName[]) { printf("Enter your age: \n"); scanf("%d", userAge); printf("Enter your name: \n"); scanf("%s", userName); return;}int main(void) { int userAge = 0; char userName[30] = ""; /* Your solution goes here */ printf("%s is %d years old.\n", userName, userAge); return 0;}

Respuesta :

Answer:

Replace

/*Your solution goes here*/

with

GetUserInfo(&userAge, userName);

And Modify:

printf("%s is %d years old.\n", userName, userAge)

to

printf("%s is %d years old.", &userName, userAge);

Explanation:

The written program declares userAge as pointer;

This means that the variable will be passed and returned as a pointer.

To pass the values, we make use of the following line:

GetUserInfo(&userAge, userName);

And to return the value back to main, we make use of the following line

printf("%s is %d years old.", &userName, userAge);

The & in front of &userAge shows that the variable is declared, passed and returned as pointer.

The full program is as follows:

#include <stdio.h>

#include <string.h>

void GetUserInfo(int* userAge, char userName[]) {

   printf("Enter your age: ");

   scanf("%d", userAge);

   printf("Enter your name: ");

   scanf("%s", userName);

   return;

}

int main(void) {

   int* userAge = 0;

   char userName[30] = "";

   GetUserInfo(&userAge, userName);

   printf("%s is %d years old.", &userName, userAge);

   return 0;  

}