Re: sprintf weirdness

"Colin Fahey" <[email protected]>
Newsgroups gmane.games.devel.windows
Message-ID <002c01c46a48$752d2920$0301a8c0@pc350>
> 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.




-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
_______________________________________________
Gamedevlists-windows mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_id=555
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.