Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!watmath!clyde!cbatt!ucbvax!YALE.ARPA!LEICHTER-JERRY
From: LEICHTER-JERRY@YALE.ARPA.UUCP
Newsgroups: mod.computers.vax
Subject: Re: printf() bug in VMS C 2.0?
Message-ID: <8612101110.AA05904@ucbvax.Berkeley.EDU>
Date: Wed, 10-Dec-86 06:10:09 EST
Article-I.D.: ucbvax.8612101110.AA05904
Posted: Wed Dec 10 06:10:09 1986
Date-Received: Sun, 14-Dec-86 00:16:47 EST
Sender: daemon@ucbvax.BERKELEY.EDU
Reply-To: 
Organization: The ARPA Internet
Lines: 28
Approved: info-vax@sri-kl.arpa

Reply-To: 

    ... [U]nder VMS C 2.0 (running on VMS 4.3)
    
    main()
    {	printf("X%2.2dX\n",2);	}
    
    will produce the output line
    X 2X
     ^
     +-[this is a blank]
    
    ...Under all versions of UNIX C compilers that I have tried, I get what I
    want:  X02X  Is this a "known bug"?  Is there some workaround which
    doesn't require using different format strings depending on the value of
    the number being printed?  (I want to print numbers in the range 0-99 and
    have them come out as precisely two digits.  And I want to do it portably
    in C.)
Assuming you are reporting accurately the format string you are using, and
the output you are getting, you have indeed discovered a bug - in "all ver-
sions of UNIX C compilers that [you] have tried"!  The documentation of printf
is quite clear:  Fields are right-justified with SPACES, not 0's.  You can
request zero fill by preceeding the field width with a 0, as in:

	printf("X%02.2dX\n",2);

							-- Jerry
-------