cutting off octal number in printf
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > cutting off octal number in printf




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    cutting off octal number in printf  
John


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-26-04 03:11 PM

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







[ Post a follow-up to this message ]



    Re: cutting off octal number in printf  
Torgny Lyon


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-26-04 03:11 PM

> 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





[ Post a follow-up to this message ]



    Re: cutting off octal number in printf  
John


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-26-04 03:11 PM

=)  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







[ Post a follow-up to this message ]



    Re: cutting off octal number in printf  
Bjorn Reese


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-26-04 03:11 PM

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






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 08:40 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register