How to implement your own atoi() function?
This program demonstrates how to implement your own atoi() function.
It uses iterative method (simplest way and easy to understand) for doing so.
You can compile this program on bOtskOOl Free Online C/C++ Compiler
//How to implement your own atoi() function
/*
**********************
www.botskool.com
**********************
*/
#include<stdio.h>
int myatoi(const char *string);
int main(int argc, char* argv[])
{
printf("\n%d\n", myatoi("2010"));
return(0);
}
int myatoi(const char *string)
{
int i;
i=0;
while(*string)
{
i=(i<<3) + (i<<1) + (*string - '0');
string++;
// Dont increment i!
}
return(i);
}
The Output is shown below.

The above OUTPUT was generated by bOtskOOl Online Compiler - Try it out now>>




Recent comments
11 weeks 10 hours ago
1 year 8 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago
1 year 12 weeks ago
1 year 13 weeks ago
1 year 14 weeks ago
1 year 14 weeks ago
1 year 18 weeks ago
1 year 18 weeks ago