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
can we implement multi-threads in c.
Why do we use & in c?
What is #include stdio h and #include conio h?
What is the benefit of using const for declaring constants?
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
Can include files be nested?
write an algorithm to display a square matrix.
Create a simple code fragment that will swap the values of two variables num1 and num2.
How can I determine whether a machines byte order is big-endian or little-endian?
Explain enumerated types in c language?
write a program fibonacci series and palindrome program in c
What is the purpose of main() function?
Tell us bitwise shift operators?
What is the use of printf() and scanf() functions?
When do you not use the keyword 'return' when defining a function a) Always b) Never c) When the function returns void d) dfd