Use built-in printf hex format code

This commit is contained in:
Peter Hill 2023-11-30 13:19:42 +00:00
parent 0c6fd78251
commit 3f4967f216
No known key found for this signature in database
GPG Key ID: 0C6B9742E72848EE
2 changed files with 2 additions and 17 deletions

View File

@ -14,13 +14,10 @@
#undef DEBUG
static char hex[16] = "0123456789abcdef";
int
main(int argc, char** argv)
{
unsigned char c;
unsigned int c0,c1;
FILE* f = NULL;
if(argc > 1) {
@ -33,12 +30,7 @@ main(int argc, char** argv)
for(;;) {
int ret = fread(&c, 1, 1, f);
if(ret != 1) break;
c1 = c;
c0 = c1 & 0xf;
c1 = (c1 >> 4);
c0 = hex[c0];
c1 = hex[c1];
printf("%c%c",(char)c1,(char)c0);
printf("%.2hhx", c);
}
if(f != stdin) fclose(f);
return 0;

View File

@ -441,13 +441,11 @@ breadthfirst(NCZMAP* map, const char* key, NClist* stack)
return stat;
}
static char hex[16] = "0123456789abcdef";
static void
printcontent(size64_t len, const char* content, OBJKIND kind)
{
size64_t i, count;
unsigned int c0,c1;
const char* format = NULL;
int strlen = 1;
@ -487,12 +485,7 @@ printcontent(size64_t len, const char* content, OBJKIND kind)
printf("%c",content[i]);
break;
default:
c1 = (unsigned char)(content[i]);
c0 = c1 & 0xf;
c1 = (c1 >> 4);
c0 = hex[c0];
c1 = hex[c1];
printf("%c%c",(char)c1,(char)c0);
printf("%.2hhx", content[i]);
}
}
}