From: "Michael Beck" Newsgroups: comp.os.msdos.djgpp Subject: Re: division after for loop Date: Sun, 7 Mar 1999 01:27:52 +0100 Organization: DResearch Lines: 43 Message-ID: <7bsh1u$cgd$1@latinum.dresearch.de> References: <36E1B306 DOT 176F24E4 AT usa DOT net> X-Complaints-To: news AT news DOT DResearch DOT DE NNTP-Posting-Date: 7 Mar 1999 00:25:34 GMT X-Newsreader: Microsoft Outlook Express 4.72.3110.5 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 NNTP-Posting-Host: router.dresearch.de X-Trace: 7 Mar 1999 01:30:00 +0100, router.dresearch.de To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Victor Senderov wrote in message <36E1B306 DOT 176F24E4 AT usa DOT net>... >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. ... > char* stgClean = "\0"; Here, you are defining a pointer, intitialy point to some location holding a '\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]; Now here, you overwrite this location. Even worser, if j gets bigger than 0, you start overwriting the data behind this location. Doing this kind you can easyly overwrite whatever data you want. If your flPart is a global defined variable, its address may be just some bytes behind the first '\0', so it gets overwritten! You must allocate an array of chars, not a char pointer. Change it to char stgClean[SOME_CONSTANT]; Than your program will work if j NEVER gets bigger than SOME_CONSTANT-1. However, best solution is to remove the temporal buffer stgClean completely... -- Michael Beck, email: beck AT dresearch DOT de