% format strings

G

grv575

For a string like print '%.*f' % (prec_length, float_var)
How does python convert this to a C printf sytle format string? Is
there a way to specify the precision length for floating points in C
format strings?
 
E

Erik Max Francis

grv575 said:
Is
there a way to specify the precision length for floating points in C
format strings?

Yes, it looks the same as in Python. Python got the notation from C.
 
Z

ziller

Erik Max Francis said:
Yes, it looks the same as in Python. Python got the notation from C.

I meant to say how does it translate the *. Python lets you use a
variable to specify the length of precision.

int f_length = 5;
float fl = 3.5
printf("%.*f", f_length, fl);

doesn't compile.
 
G

Grant Edwards

I meant to say how does it translate the *. Python lets you use a
variable to specify the length of precision.

int f_length = 5;
float fl = 3.5
printf("%.*f", f_length, fl);

doesn't compile.

Of course not. It's not valid C. The following compiles just
fine:

#include <stdio.h>

int f_length = 5;
float fl = 3.5;

void foo(void)
{
printf("%.*f",f_length, fl);
}

Not sure why you're asking C questions in c.l.p...
 
G

grv575

great thx. didn't know that was valid C. it wouldn't compile on my
end b/c of mixing C++ style include directives and C ones it looks
like.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top