[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: aplicacio per convertir numeros en "humans"



#include <stdlib.h>
#include <stdio.h>

int main(int argc , char *argv[])
{
      long num;
      if (argc < 2 ) then return 0;
      num = atol(argv[1]);
      if ((num /1000000000) > 1) {
          printf("%i G" , num /1000000000) ;
          return 0;
       }
      if ((num /1000000) > 1) {
          printf("%i M" , num /1000000) ;
          return 0;
       }
      if ((num /1000) > 1) printf("%i K" , num /1000) ;
      return 0;

guardas a sobre human.c
gcc -o human human.c



2008/4/25, Jaume Sabater <jaume@argus.net>:
> Hola
>
>  Algu sap d'alguna aplicacio en que quan li passis un numero te'l retorni en
>  format "huma"?
>
>  Es a dir, si se li passa el 10000 que et retorni un "10K", si se li passa el
>  1000000 et retorni "1M".
>
>  Es per substituir una funcio que tinc feta en bash:
>
>  Human()
>  {
>         [ $1 -gt 10000000000 ] && echo -n ` expr $1 / 1000000000 `"G"
>         [ $1 -gt 10000000 -a $1 -lt 10000000000 ] && echo -n ` expr $1 /
>  1000000 `"M"
>         [ $1 -gt 10000 -a $1 -lt 10000000 ] && echo -n ` expr $1 / 1000 `"K"
>  }
>
>  Resulta que tinc un script on s'aplica intensivament, i m'interessaria
>  agilitzar-ho.
>
>  En aquest script assumeixo que 1K=1000, pero si es 1K=1024 tambe em serveix.
>
>  PD: Perdoneu els accents, des que vaig migrar el meu PC de Debian a Ubuntu que
>  tinc certs efectes secundaris que no he lograt resoldre...
>  --
>  Jaume Sabater
>
>
>
>  --
>  To UNSUBSCRIBE, email to debian-user-catalan-REQUEST@lists.debian.org
>  with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
>
>


-- 
Pere Nubiola Radigales
Telf: +34 656316974
e-mail: pere.nubiola@gmail.com
           pnubiola@fsfe.org


Reply to: