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 the explanation for cyclic nature of data types in c?
What is n in c?
A variable that is defined in a specified portion of a program but can be used throughout the program a) global variable b) local variable c) character d) none
Where local variables are stored in c?
What is the difference between abs() and fabs() functions?
How are Structure passing and returning implemented by the complier?
What are derived data types in c?
What is the maximum no. of arguments that can be given in a command line in C.?
Why cant I open a file by its explicit path?
Find duplicates in a file containing 6 digit number (like uid) in O (n) time.
How do you declare a variable that will hold string values?
Explain what is the best way to comment out a section of code that contains comments?
What is a protocol in c?
Explain what is #line used for?
Want to know how to write a C program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.