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
Write a code on reverse string and its complexity.
How can I split up a string into whitespace-separated fields?
Why is it that not all header files are declared in every C program?
Is c procedural or functional?
I have a varargs function which accepts a float parameter?
What is structure of c program?
How to throw some light on the b tree?
Why is c faster?
Explain how do you determine a file’s attributes?
How is null defined in c?
With the help of using classes, write a program to add two numbers.
write a program that declares an array of 30 elements named "income" in the main functions. then cal and pass the array to a programmer-defined function named "getIncome" within the "getIncome" function, ask the user for annual income of 30 employees. then calculate and print total income on the screen using the following function: "void getIncome ( ai []);
What will be the outcome of the following conditional statement if the value of variable s is 10?
write a c program to calculate sum of digits till it reduces to a single digit using recursion
What is C language ?