ASCII String to integer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include <stdio.h> #include <stdbool.h> int _ASCII__String_To_Integer(const char* _String); bool Is_Digit(char character); int main(void) { int integer = _ASCII__String_To_Integer("12345"); printf("%d\n", integer); return 0; } int _ASCII__String_To_Integer(const char* _String) { int Return_Integer = 0; char element = (char)0; while (((element = *(_String++)) != (char)0) && Is_Digit(element)) Return_Integer = Return_Integer * 10 + (element - '0'); return Return_Integer; } bool Is_Digit(char character) { return (character >= (char)48 && character <= (char)57) ? true : false; // 48 = '0', 57 = '9' } | cs |
0 개의 댓글:
댓글 쓰기