www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/09/05/23:20:32

Xref: news2.mv.net comp.os.msdos.djgpp:8336
From: "Mike Marcelais" <michmarc AT microsoft DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: printf format string question
Date: 5 Sep 1996 20:00:42 GMT
Organization: Microsoft Corporation
Lines: 38
Message-ID: <01bb9b65$aab4d300$ba27379d@michmarc2>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 960905111451 DOT 363A-100000 AT is>
NNTP-Posting-Host: 157.55.39.186
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp


Eli Zaretskii <eliz AT is DOT elta DOT co DOT il> wrote in article
<Pine DOT SUN DOT 3 DOT 91 DOT 960905111451 DOT 363A-100000 AT is>...
| 
| On Wed, 4 Sep 1996, x DOT pons AT cc DOT uab DOT es wrote:
| 
| > How can specify a width fixed to 3 for the exponent of double variables
| > in printf format strings? That is to say, I want an output like
| >   3.2345E+034
| >   3.2345E+134
| 
| I don't think this is possible, at least not in ANSI C.  The ANSI 
| standard says the exponent will always have at least 2 digits, but 
| promises nothing else, and no flags are provided to have any control 
| whatsoever on the exponent field.

Sick, sick solution...


char buffer[LONG_ENOUGH];
char *walk;
int exponent;

sprintf(buffer,old_format_string,floating_point_number);
walk = strtok(buffer,"+");
sscaf(strtok(0,"+"),"%d",&exponent);
printf("%s+%03d",walk,exp);


-- 
+------------------------+----------------------+
| Mike Marcelais         | Excel Developer and  |
| michmarc AT microsoft DOT com | Magic Rules Guru     |
+------------------------+----------------------+
| Opinions expressed in this post are mine, and |
| do not necessarily reflect those of Microsoft |
+--= Moonstone Dragon =---------------= UDIC =--+

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019