Mail Archives: djgpp/1999/03/06/19:55:33
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
- Raw text -