Advertisement
dllbridge

Untitled

Feb 13th, 2025
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.82 KB | None | 0 0
  1.  
  2.  
  3. #include  <stdio.h>
  4. #include <string.h>
  5.  
  6.  
  7. float _atof(const char *p);
  8. int   _atoi(const char *p);
  9.  
  10. /////////////////////////////////////////////////////////////
  11. main()
  12. {
  13.        
  14.       char sz[99]   = "125";
  15.      
  16.       float fTDP =  _atof(sz);
  17.  
  18.       printf("fTDP =  %.1f\n", fTDP);    
  19. }
  20.  
  21.  
  22.  
  23.  
  24. //////////////////////////////////////////////////////////////
  25. float _atof(const char *sz)
  26. {
  27.        char p[77];
  28.        
  29.        strcpy(p, sz);
  30.    
  31.        int n  = strlen(p);
  32.        int nF = 0;
  33.        
  34.        if(p[n-2] == ',')
  35.        {
  36.           nF = 1;
  37.          
  38.           p[n-2] = p[n-1];
  39.                    p[n-1] = 0;
  40.        }
  41.        
  42.        float f2 = (float)_atoi(p);
  43.        
  44.        if(nF == 1) f2 /= 10;
  45.        
  46. return f2;      
  47. }
  48.  
  49.  
  50.  
  51.  
  52.  
  53. //////////////////////////////////////////////////////////////
  54. int _atoi(const char *p)
  55. {
  56.    
  57.     int n     = strlen(p),
  58.         nMult = 1;
  59.      
  60.      int nRes = 0;
  61.          
  62.      for(int i = 1; i <= n; i++)
  63.      {    
  64.          
  65.          nRes += (p[n-i] - '0') * nMult;    
  66.          
  67.          nMult *= 10;    
  68.      }      
  69.        
  70. return nRes;    
  71. }
  72.  
  73.  
  74.  
  75. /*
  76. #include  <stdio.h>
  77. #include <string.h>
  78.  
  79.  
  80. int _atoi(const char *p);
  81.  
  82.  
  83. /////////////////////////////////////////////////////////////
  84. main()
  85. {
  86.        
  87.       char sz[99]   = "78117";
  88.      
  89.       int nPassMark =  _atoi(sz);
  90.  
  91.       printf("int =  %d\n", nPassMark);    
  92. }
  93.  
  94.  
  95. //////////////////////////////////////////////////////////////
  96. int _atoi(const char *p)
  97. {
  98.    
  99.     int n     = strlen(p),
  100.         nMult = 1;
  101.      
  102.      int nRes = 0;
  103.          
  104.      for(int i = 1; i <= n; i++)
  105.      {    
  106.          
  107.          nRes += (p[n-i] - '0') * nMult;    
  108.          
  109.          nMult *= 10;    
  110.      }      
  111.        
  112. return nRes;    
  113. }
  114.  
  115. */
  116.  
  117.  
  118.  
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement