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
Why we not create function inside function.
What is C language ?
What is dangling pointer in c?
Explain which function in c can be used to append a string to another string?
What are the types of data files?
What is structure in c explain with example?
How can I dynamically allocate arrays?
how do you execute a c program in unix.
When should we use pointers in a c program?
What does p mean in physics?
Describe how arrays can be passed to a user defined function
the maximum length of a character constant can be a) 1 character b) 8 characters c) 256 chaacters d) 125 characters
In a header file whether functions are declared or defined?
to print the salary of an employee according to follwing calculation: Allowances:HRA-20% of BASIC,DA-45% of BASIC,TA-10%. Deductions:EPF-8% of BASIC,LIC-Rs.200/-Prof.Tax:Rs.200/- create c language program?
What is wrong with this code?