|
Home > Archive > Unix Programming > June 2004 > cutting off octal number in printf
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
cutting off octal number in printf
|
|
|
| I'm using stat to get the.... well, the stats of a number of files for
reporting. The st_mode for a regular file, when printed out in octal (%o
modifier), results in a number such as 100744 where the last 3 digits
(octets?) are the permissions specification. For a directory, the output is
(e.g.) 40744.
Can I instruct printf to show me only the last 4 digits of this number (ie,
0744)? Or will i have to do some string manipulation on it to get it to
print out the way I want?
Any insight is greatly appreciated.
-cjl
| |
| Torgny Lyon 2004-06-26, 10:11 am |
| > Can I instruct printf to show me only the last 4 digits of this number (ie,
> 0744)? Or will i have to do some string manipulation on it to get it to
> print out the way I want?
>
What about :
printf("%4.4o", x & 07777);
--
Torgny Lyon <torgny@enterprise.hb.se>
PGP Public Key: http://enterprise.hb.se/~torgny/pgpkey.asc
| |
|
| =) gorgeous! I wish I were clever.
Thanks!
"Torgny Lyon" <torgny@enterprise.hb.se> wrote in message
news:rSHCc.96855$dP1.319268@newsc.telia.net...
>
> What about :
>
> printf("%4.4o", x & 07777);
>
> --
> Torgny Lyon <torgny@enterprise.hb.se>
> PGP Public Key: http://enterprise.hb.se/~torgny/pgpkey.asc
| |
| Bjorn Reese 2004-06-26, 10:11 am |
| On Thu, 24 Jun 2004 21:39:35 +0000, Torgny Lyon wrote:
>
> What about :
>
> printf("%4.4o", x & 07777);
Slight improvement: use ~S_IFMT instead of the hardcoded 07777
value.
--
mail1dotstofanetdotdk
|
|
|
|
|