sprintf problem

B

Billy N. Patton

My code:
$lcname = 15;
print sprintf("| %-m.ns |\n",$lcname,4,'CELL');
print sprintf("| %m.ns |\n",$lcname,4,'CELL');
print sprintf("| %mns |\n",$lcname,4,'CELL');
print sprintf("| %s |\n",'CELL');

The results:
| %-m.ns |
| %m.ns |
| %mns |
| CELL |


I need the 'CELL' left justified, padded with spaces and using $lcname
space.

The camel book Pg 223 parag 1
The various combinations are fully documented in the manpage for
printf(3), but we'll mention that m is typically the minimum length of a
field (negative for left justified), and n is precision for exponential
formats and the maximum length for other formats. Padding is typically
done with spaces for strings ...

--
___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodlogy Group
Dallas, Texas, 214-480-4455, (e-mail address removed)
 
T

Toni Erdmann

Billy said:
My code:
$lcname = 15;
print sprintf("| %-m.ns |\n",$lcname,4,'CELL');
print sprintf("| %m.ns |\n",$lcname,4,'CELL');
print sprintf("| %mns |\n",$lcname,4,'CELL');
print sprintf("| %s |\n",'CELL');

The results:
| %-m.ns |
| %m.ns |
| %mns |
| CELL |


I need the 'CELL' left justified, padded with spaces and using $lcname
space.

The camel book Pg 223 parag 1
The various combinations are fully documented in the manpage for
printf(3), but we'll mention that m is typically the minimum length of a
field (negative for left justified), and n is precision for exponential
formats and the maximum length for other formats. Padding is typically
done with spaces for strings ...

printf "| %-*.*s |\n", $lcname, 4, 'CELL';

'*' will be replaced by the value of the parameter.

Toni
 
T

thundergnat

Billy said:
My code:
$lcname = 15;
print sprintf("| %-m.ns |\n",$lcname,4,'CELL');
print sprintf("| %m.ns |\n",$lcname,4,'CELL');
print sprintf("| %mns |\n",$lcname,4,'CELL');
print sprintf("| %s |\n",'CELL');


print sprintf("|%-".$lcname."s|\n",'CELL');
 
T

Tony Skelding

Billy N. Patton said:
My code:
$lcname = 15;
print sprintf("| %-m.ns |\n",$lcname,4,'CELL');
print sprintf("| %m.ns |\n",$lcname,4,'CELL');
print sprintf("| %mns |\n",$lcname,4,'CELL');
print sprintf("| %s |\n",'CELL');

The results:
| %-m.ns |
| %m.ns |
| %mns |
| CELL |


I need the 'CELL' left justified, padded with spaces and using $lcname
space.

The camel book Pg 223 parag 1
The various combinations are fully documented in the manpage for
printf(3), but we'll mention that m is typically the minimum length of a
field (negative for left justified), and n is precision for exponential
formats and the maximum length for other formats. Padding is typically
done with spaces for strings ...

printf "|%-${lcname}s|\n";
 

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

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top