Question: Write a C program that does the following: Converts the ASCII string 12 to an integer. Assume that the user is typing the string at
Write a C program that does the following:
Converts the ASCII string "12" to an integer. Assume that the user is typing the string at the console.
Converts the integer 12 to an ASCII string.
For more information, see Additional Notes below.
Make sure it compiles cleanly (use the Wall std=c99 options on gcc).
Make sure it is formatted cleanly and consistently.
Additional Notes
The problem has two parts:
Convert a sequence of two characters into a number. So if the user types the character '4' followed by the character '7' the program can convert this information into the integer 47.
Convert a two-digit integer (e.g. 85) into two separate characters, one for each digit, which can be found in the ASCII table.
The Module slides show the code to do this for a single-digit number, e.g. 5. However, since the problem is asking for code to do this with two-digit numbers, it is necessary to come up with a way to do the following:
In the case of part 1, we need a way to combine the numbers entered by the user into a single number. Consider that the first number entered is the tens and the second number is the units. Hence, we need to think of a number like 47 as follows:
47 = (4 * 10) + 7
In the case of part 2, we need to do the opposite, i.e., break the number into individual digits that can then be converted separately into characters. Hence, we need to think of a number like 85 as follows:
85 / 10 = 8 (integer division) 85 % 10 = 5 (remainder operation)
One more thing, we can print two characters side by side using a formatting specifier such as the one in the following code:
printf("%c%c", c1, c2); Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
