Is it legal?

X

xhungab

Hello,

Is it legal to write

printf(" %+*.*f",5,0,A[r][c]);

Instead of

printf(" %+5.0f",A[r][c]);

Thank
 
S

Schraalhans Keukenmeester

xhungab said:
Hello,

Is it legal to write

printf(" %+*.*f",5,0,A[r][c]);

Instead of

printf(" %+5.0f",A[r][c]);

Thank
You mean with the + in it ? Looks yucky anyways. Why would you want to
do this like that?
Try invoking your compiler in C90 / C99 mode, depending on which
standard you want to adhere to, and enable strict/pedantic mode.

Sh
 
S

Schraalhans Keukenmeester

Konstantin said:
Schraalhans said:
xhungab said:
Hello,

Is it legal to write

printf(" %+*.*f",5,0,A[r][c]);

Instead of

printf(" %+5.0f",A[r][c]);

Thank
You mean with the + in it ? Looks yucky anyways. Why would you want to
do this like that?
Try invoking your compiler in C90 / C99 mode, depending on which
standard you want to adhere to, and enable strict/pedantic mode.

Sh

What is wrong with the + ?

kmi
Nothing in particular, I just think it's bad coding style.
Either the actual width already is a positive and the + does not change
that, or it's a negative, in which case the + doesn't make it otherwise,
while a glimpse at the code may give the reader the suggestion it's a
positive value he/she is dealing with. As such, the + seams completely
useless here. Unless *I* have missed some other meaning of the + in this
example. In which case I'd stand corrected once you educate me further ;)

Kindest
Sh.
 
X

xhungab

It is for this function.

In this way I can choose the format for any matrices.

void p_mR(
double **A,
int e,
int d
)
{
int r;
int c;

for(r=FIRST; r<A[R_SIZE][OF]; r++)
{
printf("\n");
for (c=FIRST; c<A[C_SIZE][OF]; c++)

printf(" %+*.*f",e,d,A[r][c]);
}
printf("\n\n");
}
 
C

Christopher Benson-Manica

Schraalhans Keukenmeester said:
printf(" %+*.*f",5,0,A[r][c]);
What is wrong with the + ?
Nothing in particular, I just think it's bad coding style.

Not so. It merely indicates the programmer's desire that the numeric
output always be preceded by a '+' or a '-' sign. It means the same
thing in

printf( "%+f", A[r][c] );

and may well produce exactly the behavior the programmer requires.
useless here. Unless *I* have missed some other meaning of the + in this
example. In which case I'd stand corrected once you educate me further ;)

You did :)
 
K

Konstantin Miller

Schraalhans said:
xhungab said:
Hello,

Is it legal to write

printf(" %+*.*f",5,0,A[r][c]);

Instead of

printf(" %+5.0f",A[r][c]);

Thank
You mean with the + in it ? Looks yucky anyways. Why would you want to
do this like that?
Try invoking your compiler in C90 / C99 mode, depending on which
standard you want to adhere to, and enable strict/pedantic mode.

Sh

What is wrong with the + ?

kmi
 
F

Fred Kleinschmidt

xhungab said:
It is for this function.

What is for this function? What do you mean by "it"?
In this way I can choose the format for any matrices.

void p_mR(
double **A,
int e,
int d
)
{
int r;
int c;

for(r=FIRST; r<A[R_SIZE][OF]; r++)
{
printf("\n");
for (c=FIRST; c<A[C_SIZE][OF]; c++)

printf(" %+*.*f",e,d,A[r][c]);
}
printf("\n\n");
}
 
X

xhungab

The command :

printf(" %+*.*f",e,d,A[r][c]);

was for this function.

void p_mR(
double **A,
int e,
int d
)
{
int r;
int c;


for(r=FIRST; r<A[R_SIZE][OF]; r++)
{
printf("\n");
for (c=FIRST; c<A[C_SIZE][OF]; c++)


printf(" %+*.*f",e,d,A[r][c]);
}
printf("\n\n");
}


I use this function to print real matrices.
..
..
 
J

J. J. Farrell

xhungab said:
Hello,

Is it legal to write

printf(" %+*.*f",5,0,A[r][c]);

Instead of

printf(" %+5.0f",A[r][c]);

Yes, it's standard printf() format syntax.
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top