Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- float _atof(const char *p);
- int _atoi(const char *p);
- /////////////////////////////////////////////////////////////
- main()
- {
- char sz[99] = "125";
- float fTDP = _atof(sz);
- printf("fTDP = %.1f\n", fTDP);
- }
- //////////////////////////////////////////////////////////////
- float _atof(const char *sz)
- {
- char p[77];
- strcpy(p, sz);
- int n = strlen(p);
- int nF = 0;
- if(p[n-2] == ',')
- {
- nF = 1;
- p[n-2] = p[n-1];
- p[n-1] = 0;
- }
- float f2 = (float)_atoi(p);
- if(nF == 1) f2 /= 10;
- return f2;
- }
- //////////////////////////////////////////////////////////////
- int _atoi(const char *p)
- {
- int n = strlen(p),
- nMult = 1;
- int nRes = 0;
- for(int i = 1; i <= n; i++)
- {
- nRes += (p[n-i] - '0') * nMult;
- nMult *= 10;
- }
- return nRes;
- }
- /*
- #include <stdio.h>
- #include <string.h>
- int _atoi(const char *p);
- /////////////////////////////////////////////////////////////
- main()
- {
- char sz[99] = "78117";
- int nPassMark = _atoi(sz);
- printf("int = %d\n", nPassMark);
- }
- //////////////////////////////////////////////////////////////
- int _atoi(const char *p)
- {
- int n = strlen(p),
- nMult = 1;
- int nRes = 0;
- for(int i = 1; i <= n; i++)
- {
- nRes += (p[n-i] - '0') * nMult;
- nMult *= 10;
- }
- return nRes;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement