| www.delorie.com/archives/browse.cgi | search |
| From: | Victor Senderov <victor DOT bg AT usa DOT net> |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | division after for loop |
| Date: | Sat, 06 Mar 1999 17:58:14 -0500 |
| Organization: | Posted via RemarQ, http://www.remarQ.com - Discussions start here! |
| Lines: | 40 |
| Message-ID: | <36E1B306.176F24E4@usa.net> |
| NNTP-Posting-Host: | 209.141.72.93 |
| Mime-Version: | 1.0 |
| X-Trace: | 920761106 FQHDYQB2I485DD18DC usenet55.supernews.com |
| X-Complaints-To: | newsabuse AT remarQ DOT com |
| X-Mailer: | Mozilla 4.05 [en] (Win95; I) |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
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;
}
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |