Question: Write the C function qtoi() to convert a quaternary string to an integer. Its prototype is also described in itox.h. Write your code in le
Write the C function qtoi() to convert a quaternary string to an integer. Its prototype is also described in itox.h. Write your code in le itox.c. Your code should only accept the valid quaternary digits: 0, . . ., 3. An algorithm is as follows. 1. Start at the last character in the string, which is the least signicant digit. Remember to skip over the \0 character. 2. Convert the character to its decimal equivalent. For example, character 2 is 2. 3. Multiply the decimal number by powers of 4. The last character will be multiplied by 40, the next by 41, and so on. 4. Repeat for all of the characters in the quaternary string. 5. Sum the products
------- itox.h:
------
/* function returns in quaternaryStr the char sequence of quaternary * digits '0', '1', '2', and '3' used to represent int n. It is the * caller's responsibility to have allocated at least sizeof(int) * 4 * + 1 char's in quaternaryStr. itoq must add '\0' at the end of * quaternaryStr. */ void itoq(char quaternaryStr[], int n); /* source on right, target on left */
/* function returns an integer of the decimal value of the quaternary * characters in quaternaryStr. The function needs to check if * quaternaryStr contains only the characters '0', ..., '3'. It is * assumed that quaternaryStr has at most sizeof(int) * 4 quaternary * digits. */ int qtoi(char quaternaryStr[]); /* return the converted integer */
/* function returns in vigesimalStr the char sequence of vigesimal * digits '0', ..., '9', 'A', ..., 'J' used to represent int n. It is * the caller's responsibility to have allocated at least sizeof(int) * * 2 + 1 char's in vigesimalStr. itov must add '\0' at the end of * vigesimalStr. */ void itov(char vigesimalStr[], int n); /* source on right, target on left */
/* function returns an integer of the decimal value of the vigesimal * characters in vigesimalStr. The function needs to check if * vigesimalStr contains only the characters '0', ..., '9', 'A', ..., * 'J'. It is assumed that vigesimalStr has at most sizeof(int) * 2 * vigesimal digits. */ int vtoi(char vigesimalStr[]); /* return the converted integer */
Need all the functions listed above and would greatly appreciate that! however looking to get at least qtoi(), as the others are likely going to be done in a similar way .
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
