ascii is working
[ascii.git] / atoi.c
diff --git a/atoi.c b/atoi.c
new file mode 100644 (file)
index 0000000..5547020
--- /dev/null
+++ b/atoi.c
@@ -0,0 +1,23 @@
+#include "atoi.h"
+
+int atoi (char *str)
+{
+    int i = 0;
+    int s = 1;
+
+    if (*str == '-') {
+        s = 0;
+       str++;
+    }
+
+    while (*str != 0) {
+        if ((*str <'0') || (*str > '9')) {
+            return 0;
+        }
+        i = i * 10 + (int)(*(str++) - '0');
+    }
+
+    return (s) ? i : -i;
+}
+
+/* vim: set ts=4 sw=4 et */