Write your own C program to implement the atoi() function

int myatoi(const char* string)
{
int value = 0;

if (string)
{
while (*string && (*string <= ‘9’ && *string >= ‘0’))
{
value = (value * 10) + (*string – ‘0’);
string++;
}
}
return value;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s