#include #include #include #include #ifdef isdigit #undef isdigit #endif #define isdigit(c) ((c) >= '0' && (c) <= '9') // should test : ]212,123 - 213 -1.0 -1.1[ vvvvv float strtof__(const char *start, char **end); int main() { char *end, *start = " -12.1"; //-0.11 123 24.7 212.123 end = start; while (*start) { printf("Strtof__ is : %f\n", strtof__(start, &end)); // printf("Strtod is : %f\n", strtof(start, &end)); printf("end is : %s\n", end); if (start == end) break; start = end; } return 0; } float strtof__(const char *start, char **end){ // skip leading space characters while (*start && *start == ' ') { start++; } int negate = 1; if(*start == '-') negate = -1; if(*start == '+') start++; int retvalue = 0; while(isdigit(*start)){ printf("Shit start: %s\n", start); retvalue *= 10; retvalue = retvalue + (*start - '0'); start++; } // printf("Shit retvalue: %d and start: %s\n", retvalue, start); bool hasFp = false; if(*start == '.'){ hasFp = true; start++; } int fpsize = 1, fpvalue = 0; while(isdigit(*start)){ fpsize *= 10; fpvalue *= 10; fpvalue = fpvalue + (*start - '0'); start++; } *end = (char *)start; // printf("Before return start : %s\n", start); // printf("Shit fpvalue: %f\n", retvalue + fpvalue * 1.0/fpsize); return negate * (retvalue + fpvalue * (1.0/fpsize)); }