www.delorie.com/djgpp/bugs/show.cgi   search  
Bug 000275

When Created: 03/06/1999 17:00:07
Against DJGPP version: 2.02
By whom: victor.bg@usa.net
Abstract: problem with division after a for loop
The following is a part of a program I was trying to write. The problem is that
if the for loop is used flPart will be incorect. If it is cut everything works just
fine.

#include <iostream.h>
#include <stdlib.h>
#include <string.h>
double atod_new(char* stg);
int main()
{
atod_new("453,43.5435");
return 0;
}

double atod_new(char* stg)
{
    char* stgClean = "\0";
    int j = 0;
// THIS LOOP CAUSES 
    for (int i = 0; stg[i] != '\0'; i++) 
   {
     if (stg[i] >= '0' && stg[i] <= '9' || stg[i] == '.') stgClean[j] = stg[i];
      else j--;
       j++;
  }
    stgClean[j] = '\0';
    long intPart = atol(stgClean);
    char* point2Fl = strchr(stgClean, '.');
    point2Fl++;
    double flPart = 653.;
    cout << endl;
    cout << flPart << endl;
    flPart= flPart/10;
    cout << flPart; // THIS TO OUTPUT NONSENSE
    return flPart;
}

Solution added: 03/06/1999 23:00:26
By whom: victor.bg@usa.net
  not a bug at all!

Fixed in version on 03/06/1999 23:00:33
By whom: victor.bg@usa.net



  webmaster     delorie software   privacy  
  Copyright © 2010   by DJ Delorie     Updated Jul 2010