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
What are enums in c?
What does the error message "DGROUP exceeds 64K" mean?
What are actual arguments?
What is #define size in c?
Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
Which is an example of a structural homology?
Is main a keyword in c?
Explain what is the difference between far and near ?
What math functions are available for integers? For floating point?
What is ambagious result in C? explain with an example.
How can you call a function, given its name as a string?
The number of measuring units from an arbitarary starting point in a record,area,or control block to some other point a) recording pointer b) offset c) branching d) none
What do mean by network ?
Why & is used in c?
Can you please explain the scope of static variables?