The following code is meant to prompt you for integer input from the keyboard, read your input, and display it on the screen. The program compiles, but doesn’t work properly. Use gdb to find the bugs in the program. What are they? Fix the bugs, recompile the program, and execute it to be sure that the corrected version works. Show the working version of the program.
What will be an ideal response?
```
#include
#define PROMPT "Enter an integer: "
void get_input(char *, int *);
void main ()
{
int *user_input;
get_input(PROMPT, user_input);
(void) printf("You entered: %d.\n", user_input);
}
void get_input(char *prompt, int *ival)
{
(void) printf("%s", prompt);
scanf ("%d", ival);
}
```
The pointer user_input is being printed without dereferencing it.
```
#include
#define PROMPT "Enter an integer:"
void get_input(char *, int*);
void main()
{
int *user_input;
get_input(PROMPT,user_input);
(void) printf("You entered: %d.\n",*user_input);
}
void get_input(char *prompt, int *ival)
{
(void) printf("%s",prompt);
scanf("%d",ival);
}
```
You might also like to view...
A brochure created in Word is often separated into multiple parts
Indicate whether the statement is true or false
What is a thread in android?
A - Same as services B - Background activity C - Broadcast Receiver D - Independent dis-patchable unit is called a thread