tags:

views:

72

answers:

1

I have to output a large number, a double precision number using the following code:

fprintf(outFile,"           %11.0f   %d O(g(n))",factorialNotRecursive(index,factCount),factValue);

now the number gets so big that it jumps out of alignment further down the list of output. Once it gets past 11 digits, the max specified it continues to grow larger. Is there a way to cope with this? I'm not sure how big the inputs that will be run on this program.

+2  A: 

I think you cannot do it directly. You have to print to a string, then change the string.

/* pseudo (untested) code */

value = factorialNotRecursive(index, factCount);
/* make sure buff is large enough (or use snprintf if available) */
n = sprintf(buff, "%11.0f", value);
if (n > 11) {
    buff[10] = '+';
    buff[11] = 0;
}
fprintf(outFile,"           %s   %d O(g(n))", buff, factValue);
pmg
wow, good to know, thanks!
blakejc70