We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 957df79 commit 8322be7Copy full SHA for 8322be7
0x05-pointers_arrays_strings/100-atoic.c
@@ -0,0 +1,32 @@
1
+#include "main.h"
2
+/**
3
+ * _atoi - Convert string to integer.
4
+ * @s: Pointer to a character string.
5
+ *
6
+ * Return: void.
7
+ */
8
+
9
+int _atoi(char *s)
10
+{
11
+int sign;
12
+unsigned int num;
13
+char *temp;
14
15
+temp = s;
16
+num = 0;
17
+sign = 1;
18
+while (*temp != '\0' && (*temp < '0' || *temp > '9'))
19
20
+if (*temp == '-')
21
+sign *= -1;
22
+temp++;
23
+}
24
+if (*temp != '\0')
25
26
+do {
27
+num = num * 10 + (*temp - '0');
28
29
+} while (*temp >= '0' && *temp <= '0');
30
31
+return (num * sign);
32
0 commit comments