first commit!

This commit is contained in:
2025-02-06 12:54:34 +02:00
commit 37f9a3d138
24 changed files with 693 additions and 0 deletions

27
atoi_v2.c Normal file
View File

@ -0,0 +1,27 @@
#include <ctype.h>
#include <stdio.h>
int atoi(char string[]) {
int i, sign_ext, res;
for (i = 0; isspace(string[i]); ++i)
;
sign_ext = string[i] == '-' ? -1 : 1;
if (string[i] == '-')
++i;
for (res = 0; isdigit(string[i]); ++i) {
res = res * 10 + (string[i] - '0');
}
return sign_ext * res;
}
int main() {
printf("%d\n", atoi("123"));
printf("%d\n", atoi("-123"));
printf("%d\n", atoi("+123"));
printf("%d\n", atoi("0123"));
printf("%d\n", atoi("0123.1"));
}