Write code for atoi(x) where x is hexadecimal string.

Answer Posted / vadivel t

Hi,
Refer below link to know how atoi() lib fuction works.
http://www.cppreference.com/wiki/c/string/atoi

And find the equalent code which i have written here.

#include<stdio.h>
#include<conio.h>

int MyAtoi(char *cptr);

main()
{
/*Give different inputs like "12.3432", "a4523"," 123"
"abcd", "1234f" and find the qualent output*/

char *cptr = "123445";

printf("INTEGER EQU IS: %d\n", MyAtoi(cptr));
getch();
}
int MyAtoi(char *cptr)
{
int iptr = 0;
while((*cptr != '\0') && ((*cptr >= 48 && *cptr <= 57) ||
(*cptr == 32)))
{
if(*cptr != ' ')
iptr = (iptr * 10) + (*cptr - 48);
cptr++;
}
return iptr;
}

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

can we implement multi-threads in c.

672


Why do we use & in c?

595


What is #include stdio h and #include conio h?

605


What is the benefit of using const for declaring constants?

592


an expression contains relational operators, assignment operators, and arithmatic operstors. In the absence of parentheses, they will be evaluated in which of the following order a) assignment, relational, arithematic b) arithematic, relational, assignment c) relational, arithematic, assignment d) assignment, arithematic, relational

818






Can include files be nested?

632


write an algorithm to display a square matrix.

2229


Create a simple code fragment that will swap the values of two variables num1 and num2.

820


How can I determine whether a machines byte order is big-endian or little-endian?

628


Explain enumerated types in c language?

608


write a program fibonacci series and palindrome program in c

633


What is the purpose of main() function?

662


Tell us bitwise shift operators?

603


What is the use of printf() and scanf() functions?

640


When do you not use the keyword 'return' when defining a function a) Always b) Never c) When the function returns void d) dfd

646