Re: [GD-Windows] sprintf weirdness
Brought to you by:
vexxed72
From: Colin F. <cp...@ea...> - 2004-07-15 08:50:41
|
> Any ideas what's causing this behavior?? Could it be your "own crt0"? Hee, hee! But seriously: (1) Could it be that "buf" is somehow corrupted before you check its contents? Maybe try the following: sprintf( buf, "Hey!-->%.3f<--Look!", 0.05f ); (making sure "buf" can handle the extra text) and see that the stuff before and after the floating-point field appears in "buf" as expected. (2) Try out the following code from MSDN -- perhaps changing "_fcvt" to "_cfltcvt" as a wild guess if it fails to link with your crt0. Maybe testing cases similar to your 0.05f case with this function in particular will narrow down the problem. /* FCVT.C: This program converts the constant * 3.1415926535 to a string and sets the pointer * *buffer to point to that string. */ #include <stdlib.h> #include <stdio.h> void main( void ) { int decimal, sign; char *buffer; double source = 3.1415926535; buffer = _fcvt( source, 7, &decimal, &sign ); printf( "source: %2.10f buffer: '%s' decimal: %d sign: %d\n", source, buffer, decimal, sign ); } // Output // source: 3.1415926535 buffer: '31415927' decimal: 1 sign: 0 (3) Maybe put a memory breakpoint on "buf" to see when and how it is modified. Perhaps you'll find some unexpected modifications shortly AFTER your sprintf() call, and BEFORE your examination of the result. (4) Finally, I don't want to raise any undue panic, but you might be having psychotic hallucinations. It goes without saying that you are using your own crt0 on the advice of the voices in your head, but the question is whether or not your paranoia has you believing that space aliens tampered with your private crt0 to keep you from learning more than "0." -- after all, knowing the full value, 0.050, would expose the horrifying conspiracy. For sure the sys admins of your region of the Matrix would have to change some parameters to restore balanced gameplay. |