Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function a_to_i that converts a string of ASCII digits into a 32-bit integer. The function will receive as an argument the starting address

image text in transcribed

Write a function a_to_i that converts a string of ASCII digits into a 32-bit integer. The function will receive as an argument the starting address of the string and must return a 32-bit integer containing the integer value of the string. Assume that the string is an ASCIIZ string, i.e., ends with the null character (ASCII code 0). You don't need to check for errors in the string, i.e., you may assume the string contains only characters '0' through '9' (i.e., their corresponding ASCII codes), and will not represent a negative number or a non-decimal value or too large a number. For example, a_to_i called with the argument "12345" will return the integer 12345. Write a C program (ex1. c), where main () repeatedly reads a string from the input using fgets (), then calls a_to_i () with this string as an argument. The function a_to_i () returns an integer, which main prints using printf ("%d ", ...). The program should terminate when the integer read is 0. The name and type declaration of the function you create must be: int a_to_i(char* str) You cannot use the built-in scanf (" %d", ...) function to read the integer from the input. You must read it as a string using fgets (), and then parse it using your own a_to_i () function. For the purpose of using fgets (), you may assume that the input string will not be longer than 20 digits. For the purpose of parsing its value, you may assume that the final numerical value will not be larger than what can fit in an int variable. You cannot use the built-in atoi () function that is part of the C library. You must write your own function! For printing the value read and parsed, you should use printf (" %d ", ...)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions