walruz
walruz

Reputation: 1329

Avoid printf precision limitation

Here is a very simple code

#include <stdio.h>

void main()
{
    printf( "\n" );
    printf( "%.512x", 0xFFFFFFFF );
    printf( "\n" );
}

Problem is - I need a precision larger than 512 (print more then 512 symbols). But it looks like there is a limitation. If I replace 512 with any value that is larger - output result would not change.

I use Visual Studio 2008 and Windows XP.

Is there any way to avoid this limitation?

Upvotes: 0

Views: 114

Answers (2)

arc_lupus
arc_lupus

Reputation: 4114

You can split it up into two or more parts (with each of them shorter than 512 symbols), for example by using the modulo operator. After splitting it up, you can use two printf()-commands for printing the number without the limitation.

Upvotes: 0

jxh
jxh

Reputation: 70502

The original ANSI C (C.89) standard only states:

The minimum value for the maximum number of characters produced by any conversion shall be 509.

Later versions (C.99 and C.11) extend this to 4095 bytes. So it seems your compiler is compliant to C.89.

As a workaround, you can just print out the number of 0s you want ahead of the Fs, perhaps as a string.

char zeros[1000];
memset(zeros, '0', sizeof(zeros));
zeros[sizeof(zeros)-1] = '\0';

printf("\n%s%x\n", zeros, 0xFFFFFFFF);

Upvotes: 2

Related Questions