Skip to content

Instantly share code, notes, and snippets.

@kupp1
Last active July 11, 2018 08:01
Show Gist options
  • Save kupp1/c8c2b5ce91dcfb412cde6d59339ca5b6 to your computer and use it in GitHub Desktop.
Save kupp1/c8c2b5ce91dcfb412cde6d59339ca5b6 to your computer and use it in GitHub Desktop.
c lang atoi
#include "atoi.h"
int main (int argc, char* argv[]) {
printf("%d\n", atoi(argv[1]));
return 0;
}
#include <stdio.h>
int atoi (char str[]) { //with negative digits processing
int number = 0;
if ( ( (int)(*str) == 45 ) ) {
str++;
while(*(str) != '\0') {
if ( ( (int)(*(str)) >= 48 ) && ( (int)(*(str)) <= 57 ) ) {
number = number*10 + (*str) - '0';
} else {
return 0;
}
str++;
}
return number*(-1);
} else {
while(*(str) != '\0') {
if ( ( (int)(*(str)) >= 48 ) && ( (int)(*(str)) <= 57 ) ) {
number = number*10 + (*str) - '0';
} else {
return 0;
}
str++;
}
return number;
}
}
@supxinfy
Copy link

@kupp1, ты сумасшедший!? Ты что тут понаписал??

@kupp1
Copy link
Author

kupp1 commented Jul 10, 2018

@GIGJK special for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment