Question
Can you please help me answer the following two questions in the C programming language? Write a function called scan_decimal. The function must call scanf
Can you please help me answer the following two questions in the C programming language?
Write a function called scan_decimal. The function must call scanf using the %s format specifier, and convert the string to an int. You may only use the %s format specifier. Assume that the user will type a non-negative decimal number as input. Here is an example of its use. Lets say the user types 15
int x;
scan_decimal(&x);
printf(%d , x);
The above code should print 15
Here is the prototype for this function:
void scan_decimal(int *xptr) { char buffer[256]; char newline; *xptr = 0; scanf("%s%c", buffer, &newline); // gets rid of after the input
// please help me finish this function }
Additionally, please help me write a function called print_decimal. Just as with scan_decimal, %s is the only format specifier that you are allowed to use in print_decimal. You may assume that x is a non-negative integer. Combined with scan_decimal, here is an example of its intended use. This time, lets say the user types 373
int x;
scan_decimal(&x);
print_decimal(x);
The above code should print 373
Here is the prototype for this function:
void print_decimal(int x) {
char buffer[256];
// Please help me fill this part in
printf("%s", buffer);
}
The main function will look something like this:
int main() { int x; printf("Type a non-negative integer "); scan_decimal(&x); printf(" You typed "); print_decimal(x);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started