Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #10783

Re: fprintf internally supports print character array in hex?

From blp@cs.stanford.edu (Ben Pfaff)
Newsgroups comp.lang.c
Subject Re: fprintf internally supports print character array in hex?
Date 2011-09-23 10:32 -0700
Message-ID <87ty83411p.fsf@blp.benpfaff.org> (permalink)
References <j5ifbi$irm$1@dont-email.me>

Show all headers | View raw


mathog <dmathog@gmail.com> writes:

> Consider this code snippet:
>
> char buffer[128];
> int  i,len;
>   /* code that puts data in buffer and sets len */
> for(i=0;i<len;i++){fprintf(stdout,"%x",buffer[i]);}

You don't want %02x?

> With the newer formatting options in fprintf (like "*" and "%m") can
> the for loop now be replaced with a single fprintf like:
>
>    fprintf(stdout,"%????x",buffer,len);

No.

"*" only affects the field width or precision.  That doesn't
help.

"%m" isn't standardized.  In glibc, it prints the string
corresponding to an error code in `errno'.  That doesn't help
either.

I don't know of any extensions for this.
-- 
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa67f6aaa,0xaa9aa9f6,0x11f6},*p
=b,i=24;for(;p+=!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
2:{i++;if(i)break;else default:continue;if(0)case 1:putchar(a[i&15]);break;}}}

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

fprintf internally supports  print character array in hex? mathog <dmathog@gmail.com> - 2011-09-23 10:23 -0700
  Re: fprintf internally supports  print character array in hex? blp@cs.stanford.edu (Ben Pfaff) - 2011-09-23 10:32 -0700
    Re: fprintf internally supports  print character array in hex? mathog <dmathog@gmail.com> - 2011-09-23 10:38 -0700
  Re: fprintf internally supports  print character array in hex? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-23 18:47 +0100
    Re: fprintf internally supports  print character array in hex? mathog <dmathog@gmail.com> - 2011-09-23 12:45 -0700
      Re: fprintf internally supports  print character array in hex? blp@cs.stanford.edu (Ben Pfaff) - 2011-09-23 12:50 -0700
      Re: fprintf internally supports  print character array in hex? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-23 21:34 +0100
        Re: fprintf internally supports  print character array in hex? mathog <dmathog@gmail.com> - 2011-09-23 16:12 -0700
          Re: fprintf internally supports print character array in hex? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-09-30 01:06 -0700
          Re: fprintf internally supports  print character array in hex? "BartC" <bc@freeuk.com> - 2011-09-30 12:36 +0100
        Re: fprintf internally supports  print character array in hex? David Thompson <dave.thompson2@verizon.net> - 2011-10-03 01:11 -0400
    Re: fprintf internally supports  print character array in hex? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-09-29 21:41 +0000
  Re: fprintf internally supports print character array in hex? Gene <gene.ressler@gmail.com> - 2011-10-03 02:26 -0700

csiph-web