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 is a good data structure to use for storing lines of text?
how to print the character with maximum occurence and print that number of occurence too in a string given ?
What are the header files used in c language?
How do you determine the length of a string value that was stored in a variable?
What is volatile variable in c?
How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?
what is a function method?give example?
Why c is procedure oriented?
What is a MAC Address?
What does c value mean?
How can I access an I o board directly?
what do u mean by Direct access files? then can u explain about Direct Access Files?
How will you print TATA alone from TATA POWER using string copy and concate commands in C?
What is the purpose of main( ) in c language?
What is graph in c?