Skip to content

Instantly share code, notes, and snippets.

@stormbrew
Created February 2, 2012 05:36
Show Gist options
  • Save stormbrew/1721726 to your computer and use it in GitHub Desktop.
Save stormbrew/1721726 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int my_atoi(const char *str)
{
int neg = 1;
int x = 0;
if (*str == '-')
{
neg = -1;
*str++;
}
while (*str >= '0' && *str <= '9')
{
x *= 10;
x += *str++ - '0';
}
return neg * x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment